Jenkins pipeline script - become self aware - need directory of Jenkinsfile
There are lots of ways to do this. Here are two ways I can think of off the top of my head:
steps {
println(WORKSPACE)
}
or
steps {
def foo = sh(script: 'pwd', returnStdout: true)
println(foo)
}
In my MultiBranchPipeline I've achieved the goal using this shared library code:
#!groovy
import jenkins.model.Jenkins
String call() {
String thisMultiBranchProjectName = JOB_NAME.split('/')[0]
def thisMultiBranchProject = Jenkins.getInstance().getItemByFullName(thisMultiBranchProjectName)
def thisBranchProjectFactory = thisMultiBranchProject.getProjectFactory()
String thisStringPath = thisBranchProjectFactory.getScriptPath()
return thisStringPath
}
I do concede that this looks more like a hack…