0

I have a maven dependency graph where each of the dependency has a separate git repository.

I created each as a separate maven job and specified downstream job so that whenever a job gets triggered, the downstream jobs also get triggered recursively.

I want to achieve the same using script.

I created a pipeline script and defined all the nodes as stages.

stages {    
    stage('A') {
            steps {
             checkoutAndBuild('A.git', 'A')
            }
        }
        stage('Parallel - B, C') {
       parallel {
                stage('B') {
                     steps {
                 checkoutAndBuild('B.git', 'B') 
                     }
        }
        stage('C') {
             steps {
                 checkoutAndBuild('C.git', 'C')
             }
        }
        }
    }

    stage('D') {
       steps {
             checkoutAndBuild('D.git', 'D')
           }
        }
}

I want if commit happens in B - only B and D get triggered And if commit happens in A - the whole pipeline gets triggered.

Please suggest if I can achieve the desired behavior using script

daspilker
  • 8,154
  • 1
  • 35
  • 49
  • Not sure how in declarative way, but in scripted pipeline, you can have parameters as flags and then compare in condition, like `runStage1` and test if `runStage1` is `true` or not .. That will be probably the only way, in your care you should to have scm poll configured and each stages should be independent jobs, that can be also possible approach. – xxxvodnikxxx Apr 24 '19 at 11:29
  • Btw check that https://stackoverflow.com/questions/50566892/triggers-on-specific-stage-jenkins-pipeline there is mentioned some proprietary `checkpoints plugin` – xxxvodnikxxx Apr 24 '19 at 11:32
  • @xxxvodnikxxx, thanks for your answer. I saw the above stack overflow link but I really dont know what's the best way to solve this. This scenario is possible through the jenkins maven project. So if my dependency graph had 4 nodes, i created each one as an independent maven job using the jenkins UI. But when I look at the dependency graph it appears to me as a pipeline of multiple projects. I am not from a devops background. Would you suggest doing the Jenkins UI way where every maven project is configured as a separate maven job – Sakshi Arora Apr 24 '19 at 11:39
  • Well, from my point of view, if you can somehow get in which repo was change done, then its fine, but I think its exactly the core of the issue, I am not quite sure, but I think there was also some option to setup scm change trigger on pipelines, so independent jobs with this trigger should to solve your issues. But, if you can handle that by maven jobs somehow, then I think you dont need to use pipelines, it depends, I dont think so there is some best practice, but only personal preference. – xxxvodnikxxx Apr 24 '19 at 11:43

0 Answers0