Debian Codegraph @

docs/tutorials/jenkins_pipeline.md

raw
1 # Create a new release with Jenkins Pipelines
2
3 For this we are using the modern approach of [declarative pipelines](https://www.jenkins.io/doc/book/pipeline/).
4
5 You must also ensure your jenkins instance supports docker.
6 Most modern jenkins systems do have support for it, [they have embraced it](https://www.jenkins.io/doc/book/pipeline/docker/).
7
8 ```groovy
9 pipeline {
10 agent {
11 any
12 }
13 environment {
14 CI = 'true'
15 }
16 stages {
17 stage('Bump version') {
18 when {
19 beforeAgent true
20 expression { env.BRANCH_IS_PRIMARY }
21 not {
22 changelog '^bump:.+'
23 }
24 }
25 steps {
26 script {
27 useCz {
28 sh "cz bump --changelog"
29 }
30 // Here push back to your repository the new commit and tag
31 }
32 }
33 }
34 }
35 }
36
37 def useCz(String authorName = 'Jenkins CI Server', String authorEmail = '[email protected]', String image = 'registry.hub.docker.com/commitizen/commitizen:latest', Closure body) {
38 docker
39 .image(image)
40 .inside("-u 0 -v $WORKSPACE:/workspace -w /workspace -e GIT_AUTHOR_NAME='${authorName}' -e GIT_AUTHOR_EMAIL='${authorEmail}' -entrypoint='/bin/sh'") {
41 sh 'git config --global --add safe.directory "*"'
42 sh "git config --global user.email '${authorName}'"
43 sh "git config --global user.name '${authorEmail}'"
44 body()
45 }
46 }
47 ```
48
49 !!! warning
50 Using jenkins pipeline with any git plugin may require many configurations,
51 you'll have to tinker with it until your pipelines properly detects git events. Check your
52 webhook in your git repository and check the "behaviors" and "build strategies" in
53 your pipeline settings.