簡體   English   中英

Jenkins:如何靜態檢查使用共享庫的管道?

[英]Jenkins: how to statically check a pipeline that uses shared libraries?

我正在編寫Jenkins 管道,但我的開發過程效率極低。 對於每次修改,我必須提交和推送我的代碼,並手動運行管道。 一個簡單的錯字讓我又做了一遍。 我的版本控制日志一團糟。

我正在嘗試使用Pipeline Linter ,但它失敗了,因為它無法識別我正在使用的共享庫

這是我將嘗試整理的代碼的簡化版本。 當我從界面運行它時,此代碼有效:

//importing class MyClass defined in src/com/company/MyClass.groovy
import com.company.MyClass.* 
//importing src/com/company/helper/Log.groovy
import com.company.helper.Log;

def call(String env) {
    def mud

    pipeline {
        agent none

        stages{
            stage('Checkout') {
                agent any
                steps {
                        mud = new MyClass(script: this)
                }
            }
        }
    }
}

我使用以下命令運行管道 linter:

 ssh -p 8222 jenkins declarative-linter < myPipeline.groovy

而且,雖然在 Jenkins 中運行管道時它工作正常,但我收到以下 lint 驗證錯誤:

Errors encountered validating Jenkinsfile:
WorkflowScript: 2: unable to resolve class com.company.helper.Log
 @ line 2, column 1.
   import com.company.helper.Log;
   ^

WorkflowScript: 25: unable to resolve class MyClass
 @ line 25, column 35.
                           mud = new MyClass(script: this)

如何將管道 linter 與共享庫一起使用?

我也歡迎任何幫助簡化我的開發過程!

我找不到一個好的解決方案,所以我創建了一個管道作業,其中包含共享庫中的所有相關功能。

一旦我有了這個流程,我就可以在不提交任何東西的情況下使用它,直到它工作......

答案是無法檢查並且 Jenkins 管道開發人員注定要擁有一個非常低效的開發過程。

我剛剛發現 Jenkins 錯誤數據庫中存在與此相關的問題 我嘗試了一些解決方案,但沒有任何效果。

我仍然想要關於如何有效地對 Jenkins 管道進行編碼的任何提示。

暫無
暫無

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

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