Duplication
- Go to an agent's script console (http://<jenkins>/computer/<agent node>/script)
- Run this script
import org.jenkinsci.plugins.p4.workspace.StreamWorkspaceImpl; import org.jenkinsci.plugins.p4.groovy.P4Groovy; def ws = new StreamWorkspaceImpl('none', false, '//Stream_Depot/Main', 'job1-temp-branch1') def p4 = new P4Groovy('credential', null, ws, new FilePath(new File('workspace'))) def result = p4.run('status')
Error: 'java.lang.IllegalStateException: Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong.'
Can also be duplicated by running the following script in a Jenkinsfile
def ws = [$class: 'StreamWorkspaceImpl', charset: 'none', format: env.JOB_NAME + '-temp-' + env.BRANCH_NAME, pinHost: false, streamName: '//Stream_Depot/' + env.BRANCH_NAME] def p4 = p4(credential: 'credential', workspace: ws) def result = p4.run('streams')
Expected Result
I can use P4Groovy on an agent with no errors.
Workaround
Run P4Groovy commands in a separate stage running on the master. If data is needed, use Environment Variables to transfer variables to agent.