jenkinsci / atlassian-jira-software-cloud-plugin

Atlassian Jira Software Cloud Plugin
https://plugins.jenkins.io/atlassian-jira-software-cloud/
Apache License 2.0
43 stars 46 forks source link

Deployment integration is fired even if stage is skipped #82

Open mcascone opened 2 years ago

mcascone commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.332.2 OS: Linux - 3.10.0-1160.66.1.el7.x86_64 --- ace-editor:1.1 active-directory:2.25.1 analysis-model-api:10.10.0 ansible:1.1 ansible-tower:0.16.0 ansicolor:1.0.1 ant:475.vf34069fef73c antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 atlassian-jira-software-cloud:2.0.2 authentication-tokens:1.4 aws-credentials:191.vcb_f183ce58b_9 aws-java-sdk-ec2:1.12.215-339.vdc07efc5320c aws-java-sdk-minimal:1.12.215-339.vdc07efc5320c backup:1.6.1 blueocean:1.25.3 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.25.3 blueocean-commons:1.25.3 blueocean-config:1.25.3 blueocean-core-js:1.25.3 blueocean-dashboard:1.25.3 blueocean-display-url:2.4.1 blueocean-events:1.25.3 blueocean-git-pipeline:1.25.3 blueocean-github-pipeline:1.25.3 blueocean-i18n:1.25.3 blueocean-jira:1.25.3 blueocean-jwt:1.25.3 blueocean-personalization:1.25.3 blueocean-pipeline-api-impl:1.25.3 blueocean-pipeline-editor:1.25.3 blueocean-pipeline-scm-api:1.25.3 blueocean-rest:1.25.3 blueocean-rest-impl:1.25.3 blueocean-web:1.25.3 bootstrap4-api:4.6.0-5 bootstrap5-api:5.1.3-6 bouncycastle-api:2.26 branch-api:2.1046.v0ca_37783ecc5 build-name-setter:2.2.0 build-pipeline-plugin:1.5.8 build-user-vars-plugin:1.8 buildtriggerbadge:251.vdf6ef853f3f5 built-on-column:1.1 caffeine-api:2.9.3-65.v6a_47d0f4d1fe checks-api:1.7.4 cloudbees-bitbucket-branch-source:765.v5a_2d6a_23c01d cloudbees-folder:6.714.v79e858ef76a_2 cloudbees-jenkins-advisor:3.3.2 cobertura:1.17 code-coverage-api:2.0.4 command-launcher:81.v9c2cb_cb_db_392 conditional-buildstep:1.4.2 config-file-provider:3.10.0 configuration-as-code:1429.v09b_044a_c93de copyartifact:1.46.4 credentials:1087.1089.v2f1b_9a_b_040e4 credentials-binding:523.vd859a_4b_122e6 custom-checkbox-parameter:1.4 cvs:2.19.1 dashboard-view:2.432.va_712ce35862d data-tables-api:1.11.4-4 delivery-pipeline-plugin:1.4.2 display-url-api:2.3.6 docker-commons:1.19 docker-java-api:3.1.5.2 docker-plugin:1.2.9 docker-workflow:1.28 durable-task:496.va67c6f9eefa7 echarts-api:5.3.2-1 email-ext:2.88 embeddable-build-status:2.0.3 envinject:2.854.vfa_1657078c97 envinject-api:1.199.v3ce31253ed13 extended-choice-parameter:346.vd87693c5a_86c extensible-choice-parameter:1.8.0 external-monitor-job:191.v363d0d1efdf8 favorite:2.4.1 file-operations:1.11 file-parameters:205.vf6ce13b_e5dee filesystem-list-parameter-plugin:0.0.7 font-awesome-api:6.0.0-1 forensics-api:1.13.0 generic-webhook-trigger:1.84 ghprb:1.42.2 git:4.11.1 git-client:3.11.0 git-parameter:0.9.16 git-server:1.11 github:1.34.3 github-api:1.303-400.v35c2d8258028 github-branch-source:1628.vb_2f51293cb_78 gradle:1.38 greenballs:1.15.1 groovy:2.4 h2-api:1.4.199 handlebars:3.0.8 handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953 htmlpublisher:1.30 http_request:1.15 inedo-proget:1.4 ivy:2.2 jackson2-api:2.13.2.20220328-273.v11d70a_b_a_1a_52 jacoco:3.3.2 javadoc:217.v905b_86277a_2a_ javax-activation-api:1.2.0-3 javax-mail-api:1.6.2-6 jaxb:2.3.6-1 jdk-tool:1.5 jenkins-design-language:1.25.3 jenkins-multijob-plugin:1.36 jira:3.7.1 jjwt-api:0.11.2-71.v2722b_b_06a_2a_f jnr-posix-api:3.1.7-3 job-dsl:1.79 jobConfigHistory:1139.v888b_656ca_f6d jquery:1.12.4-1 jquery-detached:1.2.1 jquery3-api:3.6.0-3 jsch:0.1.55.2 junit:1.63 kubernetes:3580.v78271e5631dc kubernetes-client-api:5.12.1-187.v577c3e368fb_6 kubernetes-credentials:0.9.0 ldap:2.9 lockable-resources:2.15 mailer:414.vcc4c33714601 mapdb-api:1.0.9.0 matrix-auth:3.1.2 matrix-project:771.v574584b_39e60 maven-info:0.3.0 maven-plugin:3.18 metrics:4.1.6.2 momentjs:1.1.1 monitoring:1.91.0 msbuild:1.30 mstest:1.0.0 mstestrunner:1.5.0 nodejs:1.5.1 nunit:0.27 okhttp-api:4.9.3-105.vb96869f8ac3a pam-auth:1.8 parameterized-trigger:2.44 pipeline-build-step:2.18 pipeline-github-lib:36.v4c01db_ca_ed16 pipeline-graph-analysis:195.v5812d95a_a_2f9 pipeline-input-step:448.v37cea_9a_10a_70 pipeline-maven:3.10.0 pipeline-milestone-step:101.vd572fef9d926 pipeline-model-api:2.2077.vc78ec45162f1 pipeline-model-definition:2.2077.vc78ec45162f1 pipeline-model-extensions:2.2077.vc78ec45162f1 pipeline-rest-api:2.24 pipeline-stage-step:293.v200037eefcd5 pipeline-stage-tags-metadata:2.2077.vc78ec45162f1 pipeline-stage-view:2.24 pipeline-utility-steps:2.12.1 plain-credentials:1.8 plugin-util-api:2.16.0 popper-api:1.16.1-3 popper2-api:2.11.5-1 powershell:1.7 publish-over:0.22 pubsub-light:1.16 purge-build-queue-plugin:33.v59111a_551b_38 rake:1.8.0 rebuild:1.33.1 resource-disposer:0.19 role-strategy:3.2.0 run-condition:1.5 saml:2.297.v1a_dff8e51f90 scm-api:608.vfa_f971c5a_a_e9 script-security:1158.v7c1b_73a_69a_08 slack:608.v19e3b_44b_b_9ff snakeyaml-api:1.30.1 sonar:2.14 sse-gateway:1.25 ssh:2.6.1 ssh-agent:295.v9ca_a_1c7cc3a_a_ ssh-credentials:277.v95c2fec1c047 ssh-slaves:1.814.vc82988f54b_10 sshd:3.228.v4c9f9e652c86 structs:318.va_f3ccb_729b_71 subversion:2.15.5 support-core:1172.va_1fcf85806d0 theme-manager:0.6 thinBackup:1.10 timestamper:1.17 token-macro:293.v283932a_0a_b_49 translation:1.16 trilead-api:1.57.v6e90e07157e1 uno-choice:2.6.1 variant:1.4 versioncolumn:2.2 view-job-filters:2.3 windows-slaves:1.8 workflow-aggregator:2.7 workflow-api:1153.vb_912c0e47fb_a_ workflow-basic-steps:948.v2c72a_091b_b_68 workflow-cps:2689.v434009a_31b_f1 workflow-cps-global-lib:575.v24fa_0a_b_f7383 workflow-durable-task-step:1139.v252a_e12e8463 workflow-job:1180.v04c4e75dce43 workflow-multibranch:712.vc169a_1387405 workflow-scm-step:400.v6b_89a_1317c9a_ workflow-step-api:625.vd896b_f445a_f8 workflow-support:819.v37d707a_71d9b_ ws-cleanup:0.42 ```

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

Linux controller Linux on k8s agent

I don't think the OS matters in this case.

Reproduction steps

Configured the new settings for the Jenkins-Jira integration.

Disabled all my existing, explicit deploy and build integration calls.

Ran a deploy to UAT.

Expected Results

I expected deploy info to be sent to Jira for the UAT stage.

Actual Results

Deploy info was sent to Jira for EVERY stage, even those that were skipped:

[Pipeline] stage
 [Pipeline] { (Deploy To Dev)
 [INFO] deployment node was determined, envName=Dev
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='Dev', deploymentSequenceNumber=320}].
 Stage "Deploy To Dev" skipped due to when conditional
 [Pipeline] }
 [Pipeline] // stage
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='Dev', deploymentSequenceNumber=320}].
 [Pipeline] stage
 [Pipeline] { (Deploy To QA)
 [INFO] deployment node was determined, envName=QA
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='QA', deploymentSequenceNumber=320}].
 Stage "Deploy To QA" skipped due to when conditional
 [Pipeline] }
 [Pipeline] // stage
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='QA', deploymentSequenceNumber=320}].
 [Pipeline] stage
 [Pipeline] { (Deploy To UAT)
 [INFO] deployment node was determined, envName=UAT
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='UAT', deploymentSequenceNumber=320}].
 ...
a whooooole lot of deployment logging....
....
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='UAT', deploymentSequenceNumber=320}].
 [Pipeline] stage
 [Pipeline] { (Request Deploy to Production)
 Stage "Request Deploy to Production" skipped due to when conditional
 [Pipeline] }
 [Pipeline] // stage
 [Pipeline] stage
 [Pipeline] { (Deploy To Production)
 [INFO] deployment node was determined, envName=Production
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='Production', deploymentSequenceNumber=320}].
 Stage "Deploy To Production" skipped due to when conditional
 [Pipeline] }
 [Pipeline] // stage
 [INFO] SUCCESS_DEPLOYMENT_ACCEPTED: Successfully sent deployment information to Jira: consilio.atlassian.net. Accepted deployments: [DeploymentKeyResponse{pipelineId='-455079127'environmentId='Production', deploymentSequenceNumber=320}].

Anything else?

Each stage has conditionals on it, and the when clause uses the beforeAgent true directive to skip as soon as possible. I've seen in other contexts that it still "kind of" enters the stage even if the conditionals cause it to skip; perhaps that's the mechanism here.

ManneW commented 2 years ago

I've encountered the same issue as @mcascone -- the deployment integration fires even if the stage(s) matched by the regex is skipped.

I also tried, as a workaround, to nest the deployment stage in another stage, but to no avail.

Did you find any working workaround @mcascone ? :slightly_smiling_face:

mcascone commented 2 years ago

I am kind of backing into this one, as I was working with an old version of the plugin, which required manually calling the step to send the info. It also only supported a few hardcoded environment names. I was not paying close enough attention, apparently, when updating plugins on our Jenkins, as the configuration completely changed and the usage pattern too.

Naturally, the ability to have the plugin automatically send the info without having to code anything was appealing, so I ripped out all my original code, which is when I encountered this issue that I've logged.

After re-configuring the plugin with the new setup - which is pretty easy to do, thanks @jenkinsci team! - it just works again the way I had it, which was specifically calling the sendJiraDeployInfo step with a bunch of params, inside a cleanup() step that runs at the end of a pipe run.

I bet I could take out most of those params now since they're pre-defined in the plugin config. But the answer you're concerned about remains the same: call the sendJiraDeployInfo step manually when and where you want to, instead of letting it decide. Unless they fix the stage entry mechanism - which may not even fall to this plugin's devs, I don't know, it seems like a limitation on the stage design itself.