簡體   English   中英

是否有正確的方法在 jenkins 管道 groovy 腳本中調用 git clean ?

[英]Is there a proper way to call git clean in jenkins pipeline groovy script?

我不想使用checkout scm ,這就是我問的原因。 我想檢查 jenkinsfile 中的多個存儲庫並確保工作區是干凈的(git clean)

對於checkout scm ,有一個復選框可以做到這一點。 如何在 groovy 中為 git 結帳 function 重現此問題? All i've found regarding this topic is to call git clean -fdx via shell call, but I'd prefer a clean solution in groovy over a shell call, if that's possible.

  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 function。 (見上面的例子)

git 步驟方法功能是GitSCM class 的子集,指定為workflow-scm-step插件checkout方法中的參數。 如果您無法使用 class 實現該功能,那么在 step 方法中也是不可能的。

在這種情況下,step 方法的文檔確認無法進行清潔。 如問題中所述,如果您想使用 Groovy 與 Git 的綁定,則只能在checkout時進行清理。 因此,在您的情況下,您確實必須在 shell 步驟方法中使用git clean -fdx以獲得所需的功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM