Moved some of the examples to gist.github.com for organizational purposes.
Show all binding variables:
echo "${this.binding.variables}"
Change spaces in underscores for the workspace
def getWorkspace() {
pwd().replace("%2F", "_")
}
def wipeWorkspace(String workspace) {
if (workspace) {
sh "find ${workspace} -mindepth 4 -depth -delete"
}
}
Show all environment variables.
node {
sh 'env | sort'
}
Getting absolute path to a Job:
SCM_JOB is a template attribute with item -> Pipelines
[Pipeline] echo
[name:ASSEMBLY_DESCRIPTORS_BUILD,SCM_JOB:org.jenkinsci.plugins.workflow.job.WorkflowJob@3d71aee8[ShipmentEFS/COMMON/JOBS/Pipeline_leaf_caan], steps:org.jenkinsci.plugins.workflow.cps.DSL@dfb3e3d]
${SCM_JOB['fullName']} = 'ShipmentEFS/Common/Jobs/Pipeline_leaf_caan'
then we can do
node {
build job: SCM_JOB['fullName']
}
AUXILARY MODELS AND GETTNG THERE CONTENT
// List all auxilary models for logging purpose
echo "${SEFS_CONTEXT}"
echo "${SCM_MODEL}"
echo "class:${BUILD_MODEL.metaClass.toString()}"
echo "methods:${BUILD_MODEL.metaClass.methods}"
echo "fields: ${BUILD_MODEL.metaClass.fields}"
echo "toSTring: ${BUILD_MODEL.toString()}"
echo "testmodel: ${BUILD_MODEL['BUILD_TEST_MODEL']}"
try {
echo "getbinding: ${BUILD_MODEL.getValue('BUILD_TEST_MODEL')}"
} catch (error) {
echo error
}
try {
echo "model: ${BUILD_MODEL.model}"
def m=BUILD_MODEL.model
echo "meta: ${m['BUILD_TEST_MODEL']}"
} catch (error) {
echo error
echo "model: ${m.metaClass.methods}"
}
try {
echo "getmodel: ${BUILD_MODEL.getModel()}"
} catch (error) {
echo error
}