Reputation: 101
We were pretty hooked onto using some plugins which are not supported in pipelines anymore and would like to implement their usage in shared-libraries of our pipelines. One of the main items required for that would be to get hold of Jenkins Instance, can someone share a way to do that ?
Jenkins.getActiveInstance()
under "src" or "vars" folder ?I have tried to get Jenkins.getActiveInstance()
under src code as well vars code but it returns null, am I missing something here? any help will be appreciated.
thanks
Upvotes: 4
Views: 1517
Reputation: 101
This ticket can be closed, there were few issues : 1. Fix the access via (Manage Jenkins -> In script approval) 2. some scripts contain Non-cps code
Upvotes: 0
Reputation: 1805
Try 'Hudson.instance'. This pipeline below works for me on Jenkins 2.32.x. You may have to do some script approvals or turn off the sandbox.
pipeline {
agent none
stages{
stage('Instance Info') {
steps {
script {
def jenkinsInstance = Hudson.instance
for (slave in jenkinsInstance.slaves) {
echo "Slave: ${slave.computer.name}"
}
}
}
}
}
}
Bill
Upvotes: 2