jenkins - 如何静态检查使用共享库的 Jenkins 管道的代码?

标签 jenkins shared-libraries jenkins-pipeline static-analysis lint

我正在编码 Jenkins pipelines但我的开发过程效率极低。对于每次修改,我都必须提交并推送代码,并手动运行管道。一个简单的打字错误让我重蹈覆辙。我的版本控制日志一团糟。

我正在尝试使用 Pipeline Linter ,但它失败了,因为它无法识别 Shared Libraries我正在使用的。

这是我的代码的简化版本,我将尝试对其进行检查。当我从界面运行此代码时,它会起作用:

//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 管道的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52895872/

相关文章:

git - 没有这样的文件 : ‘pom.xml’ error in jenkins

c - 共享对象中的弱链接未按预期工作

jenkins - Gradle:如何将URL解析为存储库中SNAPSHOT版本的最新版本?

python - 在 bash 管道中使用时,保留 Jenkins 中 python 脚本的返回代码

android - Jenkins 构建失败,Gradle 构建守护进程意外消失

jenkins - 如何在 Jenkins 管道脚本(在 Windows 环境中)中获取文件(从工作区)的绝对路径

python - yum 找不到 libpython2.7.so.1.0()(64bit)

python - ubuntu 构建时未找到库错误

groovy - 在声明性 Jenkins 管道中的环境变量中存储值列表

jenkins - Jenkins 管道中的 java.io.NotSerializedException : sun.net.www.protocol.https.HttpsURLConnectionImpl