1

I have two pipeline jobs which are job A and job B. I need to trigger job B while job A is running.. because job A will not finish due to some API calls. so I need to start the next pipeline job B.

how can we trigger another pipeline job from the Jenkins file?
All the parallel blocks of a,b,c need to run.

Below I have pasted the job A Jenkins script.

    pipeline {
    agent any
    stages {
        stage('need to run parallelly'){
             steps {
                  parallel(
            a:{
                dir('file path'){
                bat """
                npm install
                """
                }
            },
            b:{
              dir('file path'){
                    bat """
                    npm start
                    """
                  }  
            },
            c:{
              build job: 'JOB_B'
            }
            )
        }
        }           
    }
    }
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Ojer_Dev
  • 108
  • 1
  • 12

1 Answers1

1

You have an example here.
In your case, try:

pipeline {
agent any   
stages {
    stage('need to run parallelly'){
        steps{
            script{
                parallel(
                    a:{
                        dir('file path'){
                            bat """
                            npm install
                            """
                        }
                    },
                    b:{
                        dir('file path'){
                            bat """
                            npm start
                            """
                        }  
                    },
                    "build":{
                        build job: 'JenkinsTest'
                    },
                )
            }
        }
    }
}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I am facing the problem of "Failed in branch build". But a,b is running in parallel. I am attaching my modified script once again in the below comment – Ojer_Dev Dec 26 '21 at 19:02
  • @Ojer_Dev Is the error message a natural consequence of starting npm while the installation is not yet complete? – VonC Dec 26 '21 at 20:46
  • @Ojer_Dev How did you resolve the "Failed in branch build" issue? – VonC Feb 07 '22 at 07:33
  • 1
    build step: pipeline plugin not installed in my Jenkins server. After I have installed it, the script sent by you worked for me. Thank you!!! – Ojer_Dev Feb 07 '22 at 10:20
  • @Oje perfect, well done. – VonC Feb 07 '22 at 10:36
  • Now I am modifying the pipeline script a little bit due to my project requirement. In the parallel block, step "a" is fine. Based on the npm start command in "step B" then only "step C" needs to run. if "step B" in the application failed to start, it won't trigger any job in "step C"...... How can I do that? I am trying to find out a solution. – Ojer_Dev Sep 26 '22 at 06:45
  • @Ojer_Dev Good point. I would make it a separate question to give it more visibility. – VonC Sep 26 '22 at 06:46
  • Thanks for addressing my concern in the blink of an eye. I am currently creating a new question for this. If you are okay to use that question please use that. Please let me know. I am eagerly waiting. – Ojer_Dev Sep 26 '22 at 06:53
  • @Ojer_Dev Sure, since I do not have an immediate answer, creating the question will allow others to contribute. – VonC Sep 26 '22 at 07:08
  • https://stackoverflow.com/questions/73852753/jenkins-pipeline-parellel-steps-needs-to-run-based-on-the-previous-step – Ojer_Dev Sep 26 '22 at 10:28