Hi all,
My requirement is simple, i just want to externalize some 'values' to make
my Jenkinsfile more re usable and for this i need to* load the properties
from a file which is going to be right next to Jenkinsfile, and make sure
that these properties are available anywhere in the code*. I am still new
to groovy and Jenkins code but never thought such a simple thing would be
so difficult. I enabled some methods in script security plugin but the
following code always pose error or print null. I have tried multiple
combinations and the below code is just one of them
properties = null
@NonCPS
def loadProperties() {
checkout scm
File propertiesFile = new File('${workspace}/pipeline.properties')
propertiesFile.withInputStream {
properties.load(propertiesFile)
}
}
pipeline {
agent none
stages {
stage ('prepare') {
agent any
steps {
script {
loadProperties()
echo "${properties['repo']}"
}
}
}
stage('Build') {
agent any
steps {
sh 'echo ${properties.repo}'
}
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/62422d08-9bad-4e97-8a9d-30c0879b8503%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.