Hi I started using the gitlab ci for my CI and CD. I am using Nexus for storing my jar and wars.
gitlab config
stages:
- build
- package
services:
- name: mongo:3.2.4
alias: mongodb
variables:
mongodb_hosts: "mongodb"
build_maven:
image: maven:3-jdk-8
stage: build
script:
- echo $pwd
- "./docker/wait-for-it.sh mongodb:27107 -t 30 -- git checkout master && mvn -B -Dresume=false release:prepare release:perform"
artifacts:
paths:
- target/*.jar
only:
- master
This works fine, But it triggers the build circular way. Because I am using maven release plugin for release maven artefacts.
The release plugin changes the changes the snapshot and commits back to gitlab again. in that time git lab triggers builds again, so it because circular trigger.
How to handle this properly? I like to achieve the following.
when it build the master branch, I like to release the final version to nexus and increase the version in pom file automatically like the release plugin does.
I have the following job for releasing an artifact:
Release Maven:
stage: release
image: maven:3-jdk-8
script:
- git checkout master
- git reset --hard "origin/master"
# Gitlab clones as HTTPS and there's no plan to support SSH
# The SSH key needed is built into the custom Maven image
- git remote set-url origin $SSH_GIT_URL
- mvn --batch-mode clean release:prepare release:perform -Dresume=false -DautoVersionSubmodules=true -DdryRun=false -Dmaven.test.skip=true -DskipITs -DscmCommentPrefix="[ci skip]"
The main attribute here is -DscmCommentPrefix="[ci skip]"
- this creates a commit message with a prefix, that prevents the gitlab-ci from starting a new pipeline
You can use gitlab ci except variables:
release:
stage: release
only:
- /^(release|RELEASE).*/
except:
variables:
- $CI_COMMIT_MESSAGE =~ /maven-release-plugin/
script:
- git checkout -B "$CI_COMMIT_REF_NAME"
- mvn -B release:prepare ...
More info about variables: https://docs.gitlab.com/ee/ci/variables/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With