'Hide steps, Jenkins, Groovy

Is it possible to hide a build step in jenkins pipeline? I use shared library I would like to hide (hide==it will not present on the GUI) some steps when these is not needed

Thank you,



Solution 1:[1]

First off, I presume you are trying to hide a Stage, not a Step?

If so, it is not possible to completely hide it, simply because some builds might have the stage turned on, and some might not - therefore the stage should always be there, but empty(disabled) when excluded from the build.

You need to put when { expression { return ... } } at the beginning of your stage and return any expression that evaluates to true or false depending on if you want the stage to run or not. Example code:

stage('My Test Stage') {
  when {
    expression {return <TRUE OR FALSE HERE>}
  }
         
  steps {
    ...
  }
}

Solution 2:[2]

Solution (workaround):

     stage('Steps for hide') {
      steps {
        script {
          if ( conditions == "true" ) {
                  echo "steps 1"
            }
          else if ( conditions == "false" ){
                  echo "steps 2"
          }
          else if ( conditions == "null" ) {
                  echo "No conditions step required."
          }
        }
      }
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 gh05t