jenkinsci / amazon-ecs-plugin

Amazon EC2 Container Service Plugin for Jenkins
https://plugins.jenkins.io/amazon-ecs
MIT License
192 stars 227 forks source link

Two tasks started when we have the condition in the pipeline #332

Open ivanguravel opened 9 months ago

ivanguravel commented 9 months ago

Jenkins and plugins versions report

When we have been added the condition like : ``` agent { label ENV_VAR == 'one_env' ? 'agent_one' : 'agent_two' } ``` then on the cluster side we have 2 tasks (one per agent) and choice is happening on the pipeline level (but infrastructure still creates 2 tasks). May I ask you about any workaround or fix?

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

amazon linux

Reproduction steps

  1. create the Jenkinsfile and place the agent code inside there:

    agent {  label ENV_VAR == 'one_env' ? 'agent_one' : 'agent_two' }

Expected Results

when env variable condition is happening then 1 task is running on the ecs side.

Actual Results

when env variable condition is happening then 2 tasks are running on the ecs side (one per agent).

Anything else?

also we have been tried to use additional step:

stage ("one") {
     agent { label "agent_one" }
     when {condition}

}

stage ("two") {
     agent { label "agent_two" }
     when {condition}

}

but we have still the choice between 2 agents (2 tasks on the ecs clusters).

chamacs commented 4 months ago

Just a note about the alternate test in the "Anything else?" section - That test case is not equivalent to the reported bug on this issue. By default, the "when" condition is evaluated after entering the agent. This can be changed by adding "beforeAgent true" to the "when" block. See - https://www.jenkins.io/doc/book/pipeline/syntax/#evaluating-when-before-entering-agent-in-a-stage