存储在git-reo文件中的变量可以在jenkins构建中使用吗



我正在创建一个Jenkins Freestyle构建,并在SCM中提取一个git repo。repo中的一个文件包含与构建相关的内容。如何将它们作为变量传递并在构建过程中使用。有什么插件可以利用吗?

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

你可以在";用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

最新更新