我不想使用checkout scm
,这就是我问的原因。
我想检查 jenkinsfile 中的多个存储库并确保工作区是干净的(git clean)
对于checkout scm
,有一个复选框可以做到这一点。我怎样才能在 groovy 中为 git checkout 功能重现这个?我发现的关于这个主题的所有内容都是通过 shell 调用来调用 git clean -fdx,但如果可能的话,我更喜欢 groovy 中的干净解决方案而不是 shell 调用。
def checkoutGit(def cred,def repo, def branch)
{
git credentialsId: cred, url: repo, branch: branch
}
类似于此处描述的内容: https://support.cloudbees.com/hc/en-us/articles/226122247-How-to-customize-Checkout-for-Pipeline-Multibranch
node {
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'CleanCheckout']],
userRemoteConfigs: scm.userRemoteConfigs
])
//Build, Test, Stage, Deploy
[...]
}
但不是用于 checkout ,而是用于 git 功能。 (参见上面的例子)
最佳答案
git step method功能是 GitSCM 的子集指定为 workflow-scm-step
插件 checkout
方法中的参数的类。如果您无法使用类实现该功能,那么在步骤方法中也是不可能的。
在这种情况下,步骤方法的文档确认不可能进行清理。正如问题中提到的,如果您想使用 Groovy 与 Git 的绑定(bind),则只有在 checkout
中才可能进行清理。因此,在您的情况下,您确实必须在 shell 步骤方法中使用 git clean -fdx 以获得所需的功能。
关于git - 有没有在 jenkins pipeline groovy 脚本中调用 git clean 的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67055825/