Jenkins declarative pipelines提供一个 post 指令以在阶段完成后执行代码。是否有类似的事情来运行代码在阶段运行之前,最重要的是,在 SCM 结帐之前?
例如:
pre {
always {
rm -rf ./*
}
}
这将在 checkout 源代码之前清理我的构建工作区。
最佳答案
pre
是一个很酷的功能想法,但还不存在。 skipDefaultCheckout
和 checkout scm
(与默认 checkout 相同)是键:
pipeline {
agent { label 'docker' }
options {
skipDefaultCheckout true
}
stages {
stage('clean_workspace_and_checkout_source') {
steps {
deleteDir()
checkout scm
}
}
stage('build') {
steps {
echo 'i build therefore i am'
}
}
}
}
https://stackoverflow.com/questions/45348629/