I want to merge dev and master branch every midnight and create a logfile of the application date wise. i.e dev-app-dd-mm-yy.log or master-app-dd-mm-yy.log.
My app is running on docker and ci is done by gitlab.
rules: # Workflow rules
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "main"
variables:
TAG: latest
- if: $CI_PIPELINE_SOURCE != "schedule"
variables
TAG: $CI_PIPELINE_IID
merge: # merge job to merge branches at midnight
stage: merge
script:
- git merge origin/dev && git push
build image:
stage: docker
script:
- docker build && push # build and push docker images
.deploy_template: &deploy_config
script:
- echo "Deploying application..."
- ssh -o StrictHostKeyChecking=no user@myhost # ssh into server
docker stop PRIVIOUS_CONTAINER;
docker rm PRIVIOUS_CONTAINER;
touch $ENV-app-$(date +%d.%m.%Y).log && # create a logfile with date
docker run -d -p 8080:8080
-v $ENV-app-$(date +%d.%m.%Y).log:/app/jdbcApp.log
--name app app-image:$TAG"
- echo "Application successfully deployed."
deploy:
stage: deploy
<<: *deploy_config
when: on_success
deploy latest:
stage: deploy
<<: *deploy_config
when: on_failure
Now, problem with this is merge job never returns 1. it returns "Everything up-to-date" and job passes. So no deploy is triggered when there are no push made on dev branch.