Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Individual "not" conditions seem to have different beahviour than grouping it #545

Open
roDew opened this issue Jul 15, 2022 · 0 comments
Open

Comments

@roDew
Copy link

roDew commented Jul 15, 2022

Jenkins and plugins versions report

Environment
Paste the output here

What Operating System are you using (both controller, and any agents involved in the problem)?

...

Reproduction steps

Hi guys,

I'm creating a pipeline that has a condition like that:

            stage('Create, tag, scan and push the Docker image') {
               when {
                 //1st condition
                   anyOf {
                       expression { return params.PARAM1 }
                       expression { return params.PARAM2 }
                 //2nd condition
                       allOf {
                           branch 'release/**'
                           expression { env.VARIABLE == 'something' }
                       }
                 //3rd condition
                       allOf {
                           not { branch('release/**') }
                           not { changeRequest() }
                       }
                   }
               }
               steps {
                   someCustomMethod(...)
               }
            }

And this is one of my tests I'm doing adding in my tests:

    //This test seems to not react properly to the changeRequest()
    @Test
    void "when all flags are false and not release branch but PR is open then my special method is invoked"()
    {
        def customEnv = ["COMPONENT_OWNER" : "Something", "COMPONENT_NAME" : "else", "VAR_3" : "Not compulsory"]
        addParam("PARAM1", false, true)
        addParam("PARAM2", false, true)
        addEnvVar('CHANGE_BRANCH', 'develop')
        addEnvVar('BRANCH_NAME', 'feature/blah')
        addEnvVar('BUILD_NUMBER', '10')

        myPipeline.call(customEnv)

        assertEquals(false, myspecialmethodIsInvoked)
 
        printCallStack()
        assertJobStatusSuccess()
    }

### Expected Results

I would expect that my "myspecialmethodIsInvoked" is executed only when the branch is not release and when there is not a PR, so in my case that I have a PR open, I would expect not to be executed but with the pipeline as it is, it is all the time executed because of the 3rd condition (I tested the other 2)

### Actual Results

I changed the code of the pipeline by:
                   not {
                       anyOf { 
                           branch('release/**')
                           changeRequest()
                       }
                   }
and it seems to work as I was expected with the branch, but "changeRequest" seems to ignore the setting of the CHANGE_NAME 

but it seems to ignore it.

Am I missing anything?

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant