Want to Invoke Other Jenkins Job from Declerative pipleline Not working

+2 votes

I am using following declarative  pipeline code to trigger other Jenkins pipeline job as Upstream , but its not working.

pipeline {
agent { label 'node1' }
parameters {
    string(defaultValue: "${env.VAR1_BUILD}", description: 'Choose_version', name: 'BUILD_ID')
    string(defaultValue: "docker_1", description: 'Build_Host', name: 'NODE')
    string(defaultValue: "test_scrip", description: 'Checkout Branch ', name: 'SCRIPT_BRANCH_NAME')
    string(defaultValue: "test1@gmail.com", description: 'Notification', name: 'MAIL')
    choice(choices: 'PIPELINEC', description: 'Release'Name, name: 'JOB_NAME')
    choice(choices: 'branch1', description: 'Select Release Branch', name: 'CHECKOUT_BRANCH_NAME')
    choice(choices: '.zip', description: 'Select tar ball', name: 'EXT')
  }
stages{
   stage ('Invoke_PipelineA'){
      steps{
        build job: 'PipelineA',
        parameters:  [string(name: 'BUILD_ID', value: '"${env._BUILD}"'),
                    string(name: 'NODE',  value: '"${params.NODE}"'),
                    string(name: 'SCRIPT_BRANCH_NAME', value: '"${params.SCRIPT_BRANCH_NAME}"'),
                    string(name: 'MAIL', value: '"${params.MAIL}"'),
                    choice(choices: '"${params.JOB_NAME}"', name: 'JOB_NAME'),
                    choice(choices: '"${params.CHECKOUT_BRANCH_NAME}"', name: 'CHECKOUT_BRANCH_NAME'),
                    choice(choices: '$"{params.EXT}"', name: 'EXT')]
               }
            }
  }

Please suggest whether syntax is correct or not

Apr 8, 2020 in Jenkins by anonymous
• 180 points
6,509 views
Hey, could you also please post the error that you are getting while executing this?
[Pipeline] sh
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node, dockerNode
Perhaps you forgot to surround the code with a step that provides this, such as: node,dockerNode
[Pipeline] End of Pipeline
org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node, dockerNode
	at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:261)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:247)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:180)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
	at sun.reflect.GeneratedMethodAccessor192.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:142)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:156)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:160)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.service(WorkflowScript:73)
	at WorkflowScript.run(WorkflowScript:78)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
	at sun.reflect.GeneratedMethodAccessor171.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:241)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

This probably looks like there's some issue with the syntax of your code snippet. A declarative pipeline follows a particular syntax.  For instance,

agent {
    node {
        label 'node1'
        customWorkspace '/some/other/path'
        -------
        -------
    }
}

For more info, have a look at https://jenkins.io/doc/book/pipeline/syntax/

1 answer to this question.

0 votes

Hi@atul,

As it is showing in your error required context class hudson.FilePath is missing. So import this module in your code as follows.

#!/usr/bin/env groovy
import hudson.model.*

Also check in manage jenkins and if any dependency error is there, try to resolve that first. 

answered Apr 8, 2020 by MD
• 95,460 points
Thanks to all, It fixed there was issue with passing params , Its working now.

Other question if my upstream job got triggered , So i would like to wait until this finish and then continue.

I have tried wait: true is not working . Also please paste some example how to pass choice parameter to build job in Jenkinsfile as a parameter like string
Hey, could you please post it as a separate query? And do upvote this answer in case you found it helpful.

Related Questions In Jenkins

0 votes
0 answers
+2 votes
5 answers
0 votes
1 answer

How to create one Job in Jenkins from CLI?

Hi@akhtar, You need to download the jenkins-cli.jar file ...READ MORE

answered Jul 7, 2020 in Jenkins by MD
• 95,460 points
4,049 views
0 votes
1 answer

How to remove an existing job from one view in Jenkins?

Hi@akhtar, You can remove or add jobs in ...READ MORE

answered Dec 8, 2020 in Jenkins by MD
• 95,460 points
14,423 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,079 views
+2 votes
1 answer
0 votes
1 answer

How to run Jenkins job from remote system?

Hi@akhtar, You can run your job from remote ...READ MORE

answered May 13, 2020 in Jenkins by MD
• 95,460 points
2,863 views
0 votes
1 answer

How to build one Job from Jenkins CLI?

Hi@akhtar, To build a job from Jenkins CLI, ...READ MORE

answered Jul 7, 2020 in Jenkins by MD
• 95,460 points
2,061 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP