我不想使用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
[...]
}
但不是用于结帐而是用于 git 函数。 (见上面的例子)
答案 0 :(得分:1)
git step method 功能是 GitSCM 类的子集,指定为 workflow-scm-step
插件 checkout
方法中的参数。如果您无法通过类实现功能,那么在 step 方法中也无法实现。
在这种情况下,步骤方法的文档确认无法进行清洁。如问题中所述,如果您想使用与 Git 的 Groovy 绑定,则只能在 checkout
内进行清理。因此,在您的情况下,您确实必须在 shell 步骤方法中使用 git clean -fdx
以获得所需的功能。