EN VI

jenkins handles condition unexpectedly?

2024-03-14 10:30:05
How to jenkins handles condition unexpectedly

I have a few condition commands in the jenkins script and it did not give my expected output, so I broke them down like this:

echo "PY38_RELEASE: ${env.PY38_RELEASE}"
echo "TAG_NAME: ${env.TAG_NAME}"
echo "TAG_NAME: ${env.TAG_NAME != null}"
echo "condition: ${env.PY38_RELEASE || env.TAG_NAME}"
echo "condition: ${env.PY38_RELEASE || env.TAG_NAME != null}"

Then I observe the output, and I got this:

[2024-03-14T02:18:14.115Z] PY38_RELEASE: false
[2024-03-14T02:18:14.125Z] TAG_NAME: null
[2024-03-14T02:18:14.135Z] TAG_NAME: false
[2024-03-14T02:18:14.145Z] condition: true
[2024-03-14T02:18:14.155Z] condition: true

I don't get it when the env.PY38_RELEASE is false and env.TAG_NAME != null is false, however their OR is true. Where did I get it wrong?

Solution:

I believe what's going on is that the value of env.PY38_RELEASE is the string 'false', not the boolean value false.

What I would suggest is writing in your script:

def real_py38_release = env.PY38_RELEASE && (env.PY38_RELEASE != 'false')

And then in your conditions use real_py38_release where before you had env.PY38_RELEASE.

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login