Jenkins 多分支管道 post 构建操作
Jenkins multibranch pipeline post build actions
如何为 Jenkins 多管道项目定义 post 构建操作?
当您有一个简单的项目但不适用于多管道时,有一个单独的选项可用。
当您编写管道时,您自己描述了整个流程,这使您可以非常灵活地做任何您想做的事情,包括 运行 post-build 个步骤。
您可以看到在我写的管道中使用 post-build 个步骤的示例:
https://github.com/geek-kb/Android_Pipeline/blob/master/Jenkinsfile
该代码的示例:
run_in_stage('Post steps', {
sh """
# Add libCore.so files to symbols.zip
find ${cwd}/Product-CoreSDK/obj/local -name libCore.so | zip -r ${cwd}/Product/build/outputs/symbols.zip -@
# Remove unaligned apk's
rm -f ${cwd}/Product/build/outputs/apk/*-unaligned.apk
"""
})
要将 post 构建步骤添加到多分支管道,您需要将这些步骤编码到 finally
块中,示例如下:
node {
try {
stage("Checkout") {
// checkout scm
}
stage("Build & test") {
// build & Unit test
}
} catch (e) {
// fail the build if an exception is thrown
currentBuild.result = "FAILED"
throw e
} finally {
// Post build steps here
/* Success or failure, always run post build steps */
// send email
// publish test results etc etc
}
}
对于您想要的大多数 post-build 步骤,都有关于如何以管道格式编写的在线示例。如果您有任何具体的,请在此处列出
如何为 Jenkins 多管道项目定义 post 构建操作?
当您有一个简单的项目但不适用于多管道时,有一个单独的选项可用。
当您编写管道时,您自己描述了整个流程,这使您可以非常灵活地做任何您想做的事情,包括 运行 post-build 个步骤。
您可以看到在我写的管道中使用 post-build 个步骤的示例:
https://github.com/geek-kb/Android_Pipeline/blob/master/Jenkinsfile
该代码的示例:
run_in_stage('Post steps', {
sh """
# Add libCore.so files to symbols.zip
find ${cwd}/Product-CoreSDK/obj/local -name libCore.so | zip -r ${cwd}/Product/build/outputs/symbols.zip -@
# Remove unaligned apk's
rm -f ${cwd}/Product/build/outputs/apk/*-unaligned.apk
"""
})
要将 post 构建步骤添加到多分支管道,您需要将这些步骤编码到 finally
块中,示例如下:
node {
try {
stage("Checkout") {
// checkout scm
}
stage("Build & test") {
// build & Unit test
}
} catch (e) {
// fail the build if an exception is thrown
currentBuild.result = "FAILED"
throw e
} finally {
// Post build steps here
/* Success or failure, always run post build steps */
// send email
// publish test results etc etc
}
}
对于您想要的大多数 post-build 步骤,都有关于如何以管道格式编写的在线示例。如果您有任何具体的,请在此处列出