HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

It is not allowed to use stages more than once [Jenkins_Declarative_Pipeline]

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
onceallowedjenkins_declarative_pipelinethanmorestagesusenot

Problem

I am completely new to the jenkins pipeline. I'm trying to create a project with multiple stages but in my Import stage , I want to execute parallel. For each stage in parallel , I have again multiple stages. I'm trying the following way, but getting syntax error as It is not allowed to use stages more than once.Can someone correct me how to achieve this, I have tried some online resources but unable to get clear syntax.

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'from build'
      }
    }
  }

    stage('Test_A') {
      parallel {
        stages("GUI") { stage("Tests_A") { steps {echo 'from A'}} stage("Archive") {echo 'from Publish' } }
        stages("API") { stage("Tests_B") {steps {echo 'from B'} } }
        stages("CLI") {  stage("Tests_C") {steps {echo 'from C'} }}

      }
    }

  }


I want to create something like this

Solution

Got answer from StackOverflow and here is the link to the answer.

stage('Test') {
    parallel {
        stage("Test_A") { 
            stages {
                stage("Tests_A") { steps { echo 'from A' } } 
                stage("Archieve") { steps { echo 'from Archieve' } }
            }
        }
        stage("Test_B") {
            ...
        }

        ... and so on
    }
}

Code Snippets

stage('Test') {
    parallel {
        stage("Test_A") { 
            stages {
                stage("Tests_A") { steps { echo 'from A' } } 
                stage("Archieve") { steps { echo 'from Archieve' } }
            }
        }
        stage("Test_B") {
            ...
        }

        ... and so on
    }
}

Context

StackExchange DevOps Q#11553, answer score: 2

Revisions (0)

No revisions yet.