I want to replicate my .gitlab-ci tag trigger, where gitlab will check for new tags and use that tag as the git repository to build. In jenkins, I’ve found out how to trigger it, but the repository built is not the tag. My question is:
how to use the new tag that triggers the build? Does using ‘tags/*’ as value in ‘branches to build’ always create the newest tag?
Here is my working .gitlab-ci rule, where it will use new commit tag instead of branch:
workflow:
rules:
- if: '$CI_COMMIT_TAG =~ /^v[0-9]*.[0-9]*.[0-9]*-dev-build-[0-9]*$/'
variables:
deploy_env: "development"
- if: '$CI_COMMIT_TAG =~ /^v[0-9]*.[0-9]*.[0-9]*-stg-build-[0-9]*$/'
variables:
deploy_env: "staging"
- if: '$CI_COMMIT_TAG =~ /^v[0-9]*.[0-9]*.[0-9]*-prd-build-[0-9]*$/'
variables:
deploy_env: "production"
- if: '$CI_COMMIT_TAG =~ /^v[0-9]*.[0-9]*.[0-9]*-drc-build-[0-9]*$/'
variables:
deploy_env: "production-drc"
found the solution:
- setup webhook between jenkins and gitlab (or other git provider)
- Set gitlab trigger webhook on tag events
- set ‘pipeline from scm’ refspec to ‘+refs/tags/:refs/remotes/origins/tags/‘
- Set branches to build to ‘${gitlabBranch}’ (or whatever variable sent by your WEBHOOK, not the git plugin variable GIT_BRANCH)
- Disable Lightweight Checkout
gitlab will trigger webhook to jenkins, containing the gitlabBranch variable, which will be used by ‘branches to build’.