I am not quite sure how the gitlab CI workflow should look like to achieve this:
- In my gitlab repository every feature will be developed in an own branch. At least the branch will be merged to master.
- I am using npm package grunt-bump to bump up the version of package.json
What I want to do with gitlab CI:
- For a merge to master I want to do some tests (stage test)
- If test stage has passed successfully, the merge should be done and
grunt bump
should be executed - This will bump up the version value and will do a new commit to master. This commit is always tagged like "v0.0.2" and has a message like "Release v0.0.2". Only for this commit I want to go for build stage which will build and deploy the application.
Summary
So grunt bump
should only executed if on master and after successful tests and merging. Only for the resulting commit (Release vx.x.x) the build and deploy job should be done...
Maybe there is a smarter workflow then this idea. Basicly I want to bump version value and tag the commit after merging and successful tests...
My attempt for YAML-file
stages:
- test
- build
- deploy
lint:
image: testing:latest
stage: test
tags:
- testing
script:
- /node_modules/.bin/eslint --ext .js --ext .jsx .
bump:
stage: build
tags:
- deploy
script:
- grunt bump
only:
- master
- /^Merge .*$/
build:
stage: build
tags:
- deploy
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY_IMAGE:latest
only:
- master
- tags
- /^Release .*$/
production:
stage: deploy
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:latest
- cd /home/ubuntu
- docker-compose up -d
only:
- master
- tags
- /^Release .*$/