Pipeline - How to write a declarative pipeline to invoke another job

Article ID:360019828412
1 minute readKnowledge base

Issue

  • I want a sample code of Declarative Pipeline which invokes another job

Resolution

pipeline {				//indicate the job is written in Declarative Pipeline
    agent any				//agent specifies where the pipeline will execute.
    stages {
        stage ("build") {		//an arbitrary stage name
            steps {
                build 'Pipeline_B'	//this is where we specify which job to invoke.
            }
        }
    }
}

You can use the Snippet Generator from Jenkins to generate the pipeline code. Snippet Generator can be accessed from ${JENKINS_HOME}/pipeline-syntax/

Note:

  • The build step can be used to call any project. The job which will be triggered does not have to be a pipeline.

  • You can pass additional build parameters as documented in Pipeline Build Step

Tested product/plugin versions

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.