1

How to pass upstream build number to downstream job in Pipeline job using (Trigger parameter build on other projects) ?

Agenda: To pass upstream job build number to downstream job to download upstream artefacts in downstream, here's my Jenkins pipeline script

Upstream job script:

node 
{
    stage('Build parameters')
    {
    properties([parameters([string(defaultValue: '***', description: '', name: 'version', trim: false)])])
    }/*
    echo env.BUILD_NUMBER
    def Latest_Build_Number=env.BUILD_NUMBER
    build job: 'Downstream', parameters: [[$class: 'StringParameterValue', name: 'Latest_Build_Number', value: 'env.BUILD_NUMBER', propagate:false]]    
}

**Downstream job script**:
node 
{
    stage('Downstream')
    {
    properties([[$class: 'ScannerJobProperty', doNotScan: false], parameters([string(defaultValue: '', description: '', name: 'Latest_Build_Number', trim: false)])])
echo Latest_Build_Number
}
}

Error: 
*[Pipeline] {
[Pipeline] properties
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.UnsupportedOperationException: no known implementation of class hudson.model.JobProperty is named ScannerJobProperty
    at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:478)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:402)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:514)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:388)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:341)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:282)
    at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:201)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:264)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at sun.reflect.GeneratedMethodAccessor237.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:157)
    at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:155)
    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)*
0

Remove the quotes around env.BUILD_NUMBER.

Instead of:

value: 'env.BUILD_NUMBER'

Try:

value: env.BUILD_NUMBER
0

Looks like you're missing a plugin. Remove the [$class: 'ScannerJobProperty', doNotScan: false] portion. This works:

Upstream Job

node {
    stage('Build parameters') {
        properties(
            [parameters(
                [string(
                    defaultValue: '***', 
                    description: '', 
                    name: 'version', 
                    trim: false)
                ])
            ])
    }
    echo env.BUILD_NUMBER
    def Latest_Build_Number = env.BUILD_NUMBER
    build(
        job: 'Downstream', 
        parameters: [
            [$class: 'StringParameterValue', 
             name: 'Latest_Build_Number', 
             value: env.BUILD_NUMBER, 
             propagate: false]
        ]
    )
}

Downstream Job

node {
    stage('Downstream') {
        properties([
            parameters([string(
                defaultValue: '', 
                description: '', 
                name: 'Latest_Build_Number', 
                trim: false)
            ])
        ])
        echo Latest_Build_Number
    }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.