vendredi 18 octobre 2019

If statement in parallel process jenkinsfile

I am attempting to run tasks in parallel only if certain conditions are met.

I am running a parameterized build in Jenkins where certain components that need to be deployed can be selected. With one overwriting option that builds everything in the parallel, or if certain options are selected that it only builds the selected components.

Below is a simpler version of my actual file.

node{
  properties([
    parameters([
        booleanParam(name: 'condition1', defaultValue: true, description: ''),
        booleanParam(name: 'condition2', defaultValue: false, description: ''),
        booleanParam(name: 'condition3', defaultValue: false, description: ''),
        booleanParam(name: 'condition4', defaultValue: false, description: '')

    ])
  ])
    stage('test') {
        parallel{
            'task1':{
                script {
                    if ( condition1 == true || condition2 == true){
                        echo "hello world task 1"
                    }
                }
            },
            'task2':{
                script {
                    if ( condition1 == true || condition3 == true){
                        echo "hello world task 2"
                    }
                }
            },
            'task3':{
                script {
                    if ( condition1 == true || condition4 == true){
                        echo "hello world task 3"
                    }
                }
            }
        }
    }
}

The expected output is that only the selected components are build

Aucun commentaire:

Enregistrer un commentaire