[英]Jenkins pipeline: How to build new artifacts only if has a new commit
stage('Checkout repo'){
git branch: 'mybranch',
credentialsId: '6b83e39e-1c8c-44c2-9165-b1f5a857f6cb',
url: 'git@gitlab.com:myproject.git'}
stage('run tests'){
sh 'mvn test'
}
stage('build artefact'){
sh 'mvn clean package'
}
how to run tests and make new artifact only if has a new commit? 如果有新的提交,如何运行测试并制作新的工件? without a trigger
没有触发器
You could use environment variables from the Git Plugin and create a condition: 您可以使用Git插件中的环境变量并创建条件:
if (env.GIT_COMMIT != env.GIT_PREVIOUS_SUCCESSFUL_COMMIT) {
stage('run tests'){
sh 'mvn test'
}
stage('build artefact'){
sh 'mvn clean package'
}
}
There are three ways to trigger your Jenkins job automatically. 有三种方法可以自动触发Jenkins作业。
You can use SCM polling
in your pipeline job so that it will trigger your job each time there is a change. 您可以在管道作业中使用
SCM polling
,以便每次发生更改时都会触发您的作业。
You can enable Poll SCM
under ~Build Triggers` section of your pipeline job configuration. 您可以在管道作业配置的“Build Triggers”部分下启用
Poll SCM
。
You can use Webhooks
to trigger your jobs automatically when there is a change in your GitHub
repository. 当
GitHub
存储库发生更改时,您可以使用Webhooks
自动触发作业。
Follow this documentation for Webhook
implementation. 请遵循
Webhook
实施的此文档 。
You can use post-commit
hook to trigger the job when there is a commit in your repository. 当存储库中存在提交时,您可以使用
post-commit
hook来触发作业。
Create a file called post-commit
under the .git/hooks
directory of the repository and add the following script to it: 在存储库的
.git/hooks
目录下创建一个名为post-commit
的文件,并向其添加以下脚本:
#!/bin/bash curl --user 'user:pass' -X POST "http://server.org.com/jenkins/job/JOB-NAME/build" --data token=mytoken1 --data delay=0sec
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.