[英]How to create a post-build script for all Jenkins jobs
Is there a way to create a post build script for all Jenkins jobs? 有没有办法为所有Jenkins作业创建一个后期构建脚本? Some script that is shared across jobs? 一些跨作业共享的脚本? I would like to avoid manually creating a post-build script for each job if possible. 我想尽可能避免为每个作业手动创建一个构建后的脚本。
AFAIK there is no job that will always run after any other job. AFAIK没有任何工作总是在任何其他工作之后运行。 You can emulate that creating a new job and then either configure a post build trigger on all your jobs to run the new one, or configure a build trigger in the new job to run after all the jobs you specify. 您可以模拟创建新作业,然后在所有作业上配置post构建触发器以运行新作业,或者在新作业中配置构建触发器以在指定的所有作业之后运行。
However, if all your jobs are pipelines and you have a shared library you can create a step that is actually a pipeline with a built-in post
, for example consider a step called postPipeline.groovy
: 但是,如果您的所有作业都是管道并且您有一个共享库,则可以创建一个实际上是具有内置post
的管道的步骤,例如考虑一个名为postPipeline.groovy
的步骤:
def call(Closure body) {
pipeline {
agent any
stages {
stage('Run pipeline') {
steps {
script {
body()
}
}
}
}
post {
always {
<< routine post actions go here >>
}
}
}
}
By changing all the pipelines to use this step you ensure they all run the post script: 通过更改所有管道以使用此步骤,您可以确保它们都运行post脚本:
postPipeline {
stage('Pipeline stage') {
<< code >>
}
.
.
.
}
Still, in any case you get yourself involved in manual labor. 无论如何,无论如何你都会参与体力劳动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.