Reputation: 11
I am creating a Jenkins Freestyle build and I'm pulling a git repo in the SCM. One of the files in the repo contains content related to the build. How can I pass them as variables and use them during the build. Are there any plugins which can be leveraged?
Upvotes: 1
Views: 775
Reputation: 1328982
If you are using a declarative pipelien (you can easily convert your freestyle job into such a pipeline), you can read the file, and trigger another job with, as parameters, content from that file.
You can see a (close-ish) example in "Reading file from Workspace in Jenkins with Groovy script"
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
Upvotes: 0