1
0
Fork 0
commitizen/docs/tutorials/jenkins_pipeline.md
Daniel Baumann 167a3f8553
Adding upstream version 4.6.0+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2025-04-21 11:40:48 +02:00

53 lines
1.7 KiB
Markdown

# Create a new release with Jenkins Pipelines
For this we are using the modern approach of [declarative pipelines](https://www.jenkins.io/doc/book/pipeline/).
You must also ensure your jenkins instance supports docker.
Most modern jenkins systems do have support for it, [they have embraced it](https://www.jenkins.io/doc/book/pipeline/docker/).
```groovy
pipeline {
agent {
any
}
environment {
CI = 'true'
}
stages {
stage('Bump version') {
when {
beforeAgent true
expression { env.BRANCH_IS_PRIMARY }
not {
changelog '^bump:.+'
}
}
steps {
script {
useCz {
sh "cz bump --changelog"
}
// Here push back to your repository the new commit and tag
}
}
}
}
}
def useCz(String authorName = 'Jenkins CI Server', String authorEmail = 'your-jenkins@email.com', String image = 'registry.hub.docker.com/commitizen/commitizen:latest', Closure body) {
docker
.image(image)
.inside("-u 0 -v $WORKSPACE:/workspace -w /workspace -e GIT_AUTHOR_NAME='${authorName}' -e GIT_AUTHOR_EMAIL='${authorEmail}' -entrypoint='/bin/sh'") {
sh 'git config --global --add safe.directory "*"'
sh "git config --global user.email '${authorName}'"
sh "git config --global user.name '${authorEmail}'"
body()
}
}
```
!!! warning
Using jenkins pipeline with any git plugin may require many different configurations,
you'll have to tinker with it until your pipelines properly detects git events. Check your
webhook in your git repository and check the "behaviors" and "build strategies" in
your pipeline settings.