Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Conditional Step Check if ENV variable is set

How can I use the Conditional Step Jenkins plugin, to check if an environment variable is set? If it is set, proceed as normal. If it is not set, skip the post-build actions and mark build as a pass (not a failure).

Or if there is a way to do this without using the Conditional Step plugin, I would be open to that as well.

like image 764
CodyK Avatar asked Jan 08 '16 20:01

CodyK


People also ask

Can we run a step conditionally in Jenkins?

The Conditional BuildStep plugin lets users add conditional logic to Freestyle jobs from within the Jenkins web UI. It does this by: Adding two types of Conditional BuildStep ("Single" and "Multiple") - these build steps contain one or more other build steps to be run when the configured condition is met.

In which section of Manage Jenkins the environ variables are declared?

Jenkinsfile We can set environment variables globally by declaring them in the environment directive of our Jenkinsfile. This approach of defining the variables in the Jenkins file is useful for instructing the scripts; for example, a Make file.


1 Answers

You could do this with the Flexible Publish plugin. Under Conditional action select Not, then under that select Strings match. Put your environment variable as String 1 and leave String 2 empty. Then add your post-build actions below.

enter image description here

like image 78
EricP Avatar answered Sep 20 '22 11:09

EricP