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?
Asked
Active
Viewed 495 times
1 Answers
0
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

VonC
- 1,262,500
- 529
- 4,410
- 5,250
-
i have created 4 jobs using jenkins job builder , All the 4 jobs use different repo. In each repo there is file with corresponding mail list which needs to be read and updated in the post build step. I was looking for an option to read the contents of file as variable from a file in workspace and update it in postbuild – Thani Jun 07 '21 at 11:08
-
@Thani Exactly: what my answer illustrates is how to read that file. You can then assign it to an environment variable: https://stackoverflow.com/a/53525173/6309 – VonC Jun 07 '21 at 12:24