How to write conditional step with boolean parameter in jenkins scripted pipeline job?

Davis8988

This condition in my script always gets evaluated as true and prints "Yes equal - running the stage"

stage('test cond'){  
    if(env.BUILD_TESTING2 == true){  
        echo "Yes equal - running the stage"
    } else {
        echo "Not equal - skipping the stage"
    }
}  

Even if I start the build by setting env.BUILD_TESTING2 = false it still enters the condition and prints "Yes equal - running the stage".

I also tried this syntax:

stage('test cond'){  
    if(env.BUILD_TESTING2){  
        echo "Yes equal - running the stage"
    } else {
        echo "Not equal - skipping the stage"
    }
}

But it also still always gets evaluated as true.

How can I write a conditional step with boolean parameter in Jenkins scripted pipeline ?

Krzysztof Błażełek

You need to convert this environment variable (of type string) to boolean using toBoolean() function:

stage('test cond'){  
    if(env.BUILD_TESTING2.toBoolean()){  
        echo "Yes equal - running the stage"
    } else {
        echo "Not equal - skipping the stage"
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Conditional step/stage in Jenkins pipeline

From Java

Jenkins scripted pipeline or declarative pipeline

From Dev

how to disable jenkins pipeline job

From Dev

Select job as parameter in Jenkins (Declarative) Pipeline

From Java

Is it possible to make a parameterized scripted pipeline in Jenkins by listing the parameters in actual script, not in job config

From Dev

Allow same Jenkins job to be launched only after a certain step in the pipeline

From Dev

How to trigger Multibranch Pipeline Jenkins Job within regular pipeline job?

From Java

How to add a timeout step to Jenkins Pipeline

From Dev

How to trigger jenkins pipeline job by scm change?

From Dev

How to pass information in a Jenkins pipeline job

From Dev

Jenkins - How to replay lastSuccessfulBuild inside pipeline job

From Dev

How do I use Jenkins Pipeline properties step?

From Dev

Jenkins User Acceptance step in pipeline

From Dev

Jenkins Pipeline Fails if Step is Unstable

From Dev

Jenkins Pipeline sh step hangs

From Dev

How to re-write a Jenkins DSL file as a Jenkins pipeline jenkinsfile?

From Dev

Get env property by dynamic key in Jenkins scripted pipeline

From Dev

How do I remove an unstoppable pipeline job in Jenkins?

From Dev

How to trigger a Jenkins 2.0 Pipeline job from a GitHub pull request

From Dev

How to use the Jenkins Heavy Job Property with Pipeline Jobs

From Dev

How to make Jenkins automatically add webhook for Pipeline job?

From Dev

Skip step based on job parameter

From Dev

Skip step based on job parameter

From Dev

How to add conditional postbuild actions using jenkins Declarative Pipeline?

From Dev

Jenkins EnvInject plugin + Pipeline job

From Dev

Jenkins Job Builder - Automatic Pipeline Job

From Dev

How to pass boolean parameter value in pipeline to downstream jobs?

From Dev

How to use a parameter from NodeLabelParameter Plugin with the "build" step of Jenkins Workflow

From Dev

Jenkins Build Pipeline Plugin - Blank White modal window - no parameter prompt issue on first job

Related Related

  1. 1

    Conditional step/stage in Jenkins pipeline

  2. 2

    Jenkins scripted pipeline or declarative pipeline

  3. 3

    how to disable jenkins pipeline job

  4. 4

    Select job as parameter in Jenkins (Declarative) Pipeline

  5. 5

    Is it possible to make a parameterized scripted pipeline in Jenkins by listing the parameters in actual script, not in job config

  6. 6

    Allow same Jenkins job to be launched only after a certain step in the pipeline

  7. 7

    How to trigger Multibranch Pipeline Jenkins Job within regular pipeline job?

  8. 8

    How to add a timeout step to Jenkins Pipeline

  9. 9

    How to trigger jenkins pipeline job by scm change?

  10. 10

    How to pass information in a Jenkins pipeline job

  11. 11

    Jenkins - How to replay lastSuccessfulBuild inside pipeline job

  12. 12

    How do I use Jenkins Pipeline properties step?

  13. 13

    Jenkins User Acceptance step in pipeline

  14. 14

    Jenkins Pipeline Fails if Step is Unstable

  15. 15

    Jenkins Pipeline sh step hangs

  16. 16

    How to re-write a Jenkins DSL file as a Jenkins pipeline jenkinsfile?

  17. 17

    Get env property by dynamic key in Jenkins scripted pipeline

  18. 18

    How do I remove an unstoppable pipeline job in Jenkins?

  19. 19

    How to trigger a Jenkins 2.0 Pipeline job from a GitHub pull request

  20. 20

    How to use the Jenkins Heavy Job Property with Pipeline Jobs

  21. 21

    How to make Jenkins automatically add webhook for Pipeline job?

  22. 22

    Skip step based on job parameter

  23. 23

    Skip step based on job parameter

  24. 24

    How to add conditional postbuild actions using jenkins Declarative Pipeline?

  25. 25

    Jenkins EnvInject plugin + Pipeline job

  26. 26

    Jenkins Job Builder - Automatic Pipeline Job

  27. 27

    How to pass boolean parameter value in pipeline to downstream jobs?

  28. 28

    How to use a parameter from NodeLabelParameter Plugin with the "build" step of Jenkins Workflow

  29. 29

    Jenkins Build Pipeline Plugin - Blank White modal window - no parameter prompt issue on first job

HotTag

Archive