小编Vat*_*ngh的帖子

如何在 jenkinsfile 中定义和使用函数?

我想将 git diff shell 脚本的输出检索到变量中,然后在其上运行用户定义的函数。我如何声明我想要编写的这些函数以及如何使用它们?

pipeline{
agent any
parameters {
        string(name: 'branchA', defaultValue: 'master', description: 'Comapare which branch?')

        string(name: 'branchB', defaultValue: 'dev', description: 'Compare with which branch?')
}

stages {
    stage('Build') {
        steps{
            checkout([$class: 'GitSCM',
                branches: [[name: '*/master']],
                doGenerateSubmoduleConfigurations: false,
                extensions: [[$class: 'CleanBeforeCheckout']],
                submoduleCfg: [],
                userRemoteConfigs:  [[credentialsId: 'gitCreds', url: "https://github.com/DialgicMew/example.git"]]])
 
                sh "git diff --name-only remotes/origin/${params.branchA} remotes/origin/${params.branchB}"    
         }
    
    stage('Functions on the result') {
        steps{
            echo "Functions to be used here"
        }
    }
}
}
```




Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-groovy jenkins-pipeline

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

jenkins ×1

jenkins-groovy ×1

jenkins-pipeline ×1