1

我正在创建一个 Jenkins Freestyle 构建,并且我正在 SCM 中提取一个 git repo。存储库中的文件之一包含与构建相关的内容。如何将它们作为变量传递并在构建期间使用它们。有没有可以利用的插件?

4

1 回答 1

0

如果您使用的是声明式管道(您可以轻松地将您的自由式作业转换为这样的管道),您可以读取该文件,并使用该文件中的内容作为参数触发另一个作业。

您可以在“使用 Groovy 脚本从 Jenkins 的 Workspace 中读取文件”中看到一个(接近的)示例

pipeline {
   agent any

   stages {
      stage('Hello') {
         steps {
            script{
               git branch: 'Your Branch name', credentialsId: 'Your crendiatails', url: ' Your BitBucket Repo URL '
          
               def filePath = readFile "${WORKSPACE}/ Your File Location"                   
               def lines = filePath.readLines() 
               for (line in lines) {                                            
                  build(job: "anotherjob",
                        parameters:[$line]
               } // for
            } // script
         }// steps
      } // stage
   } // stages
} // pipeline
于 2021-06-03T09:39:09.027 回答