CircleCI-Public / jira-connect-orb

Display the status of CircleCI workflows and deployments in Jira!
https://circleci.com/orbs/registry/orb/circleci/jira
MIT License
25 stars 27 forks source link

Jira tickets not detected on tag releases #58

Closed mbajur closed 1 year ago

mbajur commented 3 years ago

Orb version

1.3.0

What happened

Hello!

I'm trying to use https://circleci.com/developer/orbs/orb/circleci/jira orb in one of my projects based on gitflow. So, basically, i have two main branches - master and dev. All the ongoing work is merged into dev and once the version/sprint is complete, i merge dev into master. Hotfixes goes straight to master.

Here is my circleci config file:

version: 2.1

orbs:
  webhook: eddiewebb/webhook@volatile
  jira: circleci/jira@1.3.0

jobs:
  build_test:
    working_directory: ~/xxx
    docker:
      - image: circleci/ruby:2.7.0-node-browsers
        environment:
          RAILS_ENV: test
          DATABASE_URL: postgres://root@127.0.0.1:5432/xxx
      - image: circleci/redis:5.0.3
      - image: circleci/postgres:11.6
        environment:
          RAILS_ENV: test
          POSTGRES_USER: root
          POSTGRES_DB: xxx

    steps:
      - checkout
      - run:
          name: Run RSpec tests
          command:
            bundle exec rspec --format RspecJunitFormatter -o
            /home/circleci/pass-manager/test-results/rspec/rspec.xml -p
      - jira/notify

  deploy_staging:
    working_directory: ~/xxx
    docker:
      - image: circleci/node:10
    steps:
      - webhook/notify:
          endpoint: xxx
      - jira/notify

  deploy_production:
    working_directory: ~/xxx
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - jira/notify

workflows:
  version: 2
  test_and_deploy:
    jobs:
      - build_test
      - deploy_staging:
          post-steps:
            - jira/notify:
                environment: staging
                environment_type: staging
                job_type: deployment
          requires:
            - build_test
          filters:
            branches:
              only: dev

  deploy_production_notify:
    jobs:
      - deploy_production:
          post-steps:
            - jira/notify:
                environment: production
                environment_type: production
                job_type: deployment
          filters:
            # ignore any commit on any branch by default
            branches:
              ignore: /.*/
            # only act on version tags
            tags:
              only: /^v.*/

And the thing is - when i'm merging my PRs into dev branch, all works perfectly well and deployment statuses of tasks are being reported to Jira. On the other hand, when i merge into master and do a deployment on there *(using tags v.)**, jira orb reports that it was not able to find any issue keys.

jira/notify of deploy_production job output:

{
  "acceptedBuilds": [],
  "rejectedBuilds": [
    {
      "key": {
        "pipelineId": "xxx",
        "buildNumber": 540
      },
      "errors": [
        {
          "message": "At least one 'issueKeys' is required"
        }
      ]
    }
  ],
  "unknownIssueKeys": []
}

jira/notify of deploy_production_notify workflow output:

ERROR: unknown association
{
  "acceptedDeployments": [],
  "rejectedDeployments": [
    {
      "key": {
        "pipelineId": "xxx",
        "environmentId": "xxx",
        "deploymentSequenceNumber": 540
      },
      "errors": [
        {
          "message": "No valid associations found for deployment"
        }
      ]
    }
  ],
  "unknownIssueKeys": [],
  "unknownAssociations": [
    {
      "associationType": "serviceIdOrKeys",
      "values": [
        ""
      ]
    }
  ]
}

What's interesting is that merging master back to dev (obviously) triggers the deployment notification and jira deployment notification works in there properly! Which makes me think it's nothing strictly related to jira orb itself and that it has something to do with a fact that I'm using tags/releases.

Thanks in advance for any clues.

dsayling commented 3 years ago

@mbajur - you are correct, the tag based filter is the problem.

Here you can see the command fetch the current job info from circleci - this job info is then used in the following line with jq to parse the job details and search for the jira in the subject/body keys.

Workflows triggered via a 'tag' do not have these fields set

  },
  "status" : "success",
  "committer_name" : null,
  "retries" : [ 331 ],
  "subject" : null,
  "vcs_type" : "github",
  "timedout" : false,
  "dont_build" : null,
  "lifecycle" : "finished",
  "no_dependency_cache" : false,
  "stop_time" : "2021-01-13T22:01:18.697Z",
  "ssh_disabled" : true,
mbajur commented 3 years ago

Does it mean using this orb is not possible with tag-based deploys?

dsayling commented 3 years ago

@mbajur with the way it's currently built, it wouldn't work for tag-based filters, yes. I will discuss this with the team internally to see if we can get some time to enhance this.

For now (I know, not ideal), you could do your own tag checks in the job itself. Here's a pseudo config example:


  deploy_production_notify:
    jobs:
      - deploy_production:
          pre-steps:
            # e.g. this step would fail if there's not a tag for the pushed sha and it doesn't meet a valid semver regex
            - run: git fetch --tags && git describe --exact-match | sed -nre 's/^[^0-9]*(([0-9]+\.)*[0-9]+).*/\1/p'
          post-steps:
            - jira/notify:
                environment: production
                environment_type: production
                job_type: deployment
          filters:
            branches:
              only: /master/
gmemstr commented 3 years ago

We're making some small changes in #61 which would allow for manual setting of the Jira tag, rather than scanning the commit message for it - there are some instructions in that PR on how to test it :) @mbajur

mbajur commented 3 years ago

thank you @gmemstr ! I will test that soon

chowes-electricai commented 3 years ago

Is this codebase still maintained? I'd love to see this feature implemented

suhaasprasad commented 2 years ago

+1 would love to see this resolved

foresx commented 2 years ago

Is there any plan to fix this problem? Kind of important for our workflow

weaselmetal commented 1 year ago

We have a very similar git workflow as described in the original post. We don't filter on tags, though. What we'd like is that all the commits from our develop branch that got merged into master are picked up and reported as being part of this deployment, which isn't the case. I suppose our problem is at least related?

KyleTryon commented 1 year ago

Hello Friends 👋

The day has finally come 🎉 ! As we have alluded to in a few spots in this repository, we have been working on a new integration for Jira with CircleCI to replace this outdated orb which has historically been difficult for us to update. Today we are excited to announce Jira Integration V2 is finally LIVE!

New Docs: https://circleci.com/docs/jira-plugin/ Orb v2:

Atlassian Forge App: https://github.com/CircleCI-Public/circleci-for-jira

Key Features

What to know