This is my gitlab pipeline:
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
SPRING_PROFILES_ACTIVE: gitlab-ci
before_script:
- git remote set-url origin https://gitlab-ci-token:$CICD_GIT_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
- git config --global user.email '[email protected]'
- git config --global user.name 'Gitlab (Me)'
- git checkout -b $CI_COMMIT_BRANCH
stages:
- build
- package
- deploy
gradle-build:
image: gradle:alpine
stage: build
script:
- PROJECT_VERSION=`./gradlew -quiet printVersion`
- ./gradlew release
artifacts:
paths:
- build/libs/*.jar
docker-build:
stage: package
script:
- docker build -t registry.gitlab.com/me/myproject:$PROJECT_VERSION .
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker push registry.gitlab.com/me/myproject:PROJECT_VERSION
Not sure why the 3 builds get triggered (maybe because the plugin does a commit) and not sure how to fix this.
Any help would be appreciated.
Thanks.
After taking a look here: https://docs.gitlab.com/ee/ci/yaml/
I added the following section to the pipeline:
Moved the stuff in "before_script" under script, and changed the git username:
Now the commits with the name "Gitlab Pipeline" don't trigger a build anymore.
The extra builds were triggered because the release plugin also does a pre-tag commit, followed by a new version commit at the end. This would trigger 2 builds, which in turn would each trigger 2 more and so on.
Now the pipeline behaves as expected.