diff --git a/README.md b/README.md index 7d03dbc..a415335 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,11 @@ This command receives the following parameters to performs the API calls: deployments. - `acsf-user`: Sets the acsf user account. - `acsf-site`: Sets the project site. You can get this value looking at your acsf url: `https://www.[env]-[site].acsitefactory.com` +- `slack-channel`: The Slack Channel to send notifications. +- `with-jira`: Boolean. If set to "true" it will transition tickets on the Jira project. +- `jira-transition-id`: The Jira transition ID. +- `jira-url`: The Jira Cloud URL +- `jira-project`: The Jira Project key for which we should transition tickets. **NOTE**: To perform API calls to the site factory is recommended to create a "machine" user in the site factory (in each environment!). This user should have the role "release engineer" to have the correct permissions to use the @@ -78,6 +83,7 @@ This command receives the following parameters: - `env`: The environment where to deploy. It's default value is "test" - `jira-url`: The Jira Cloud URL - `jira-transition-id`: The Jira transition ID +- `jira-project`: The Jira project key, to transition only tickets in the specified project. **NOTE:** To avoid setting the auth token in your config files, you must define it as an CircleCI Environment Variable. diff --git a/src/commands/jira-transition.yml b/src/commands/jira-transition.yml index e72db68..ed319cc 100755 --- a/src/commands/jira-transition.yml +++ b/src/commands/jira-transition.yml @@ -25,10 +25,14 @@ parameters: jira-transition-id: type: string default: "" - description: "The Jira transition ID" + description: 'The Jira transition ID' jira-auth: type: env_var_name default: JIRA_AUTH + jira-project: + type: string + default: "" + description: 'The Jira Project key for which we should transition tickets.' steps: - run: when: on_success @@ -41,4 +45,5 @@ steps: JIRA_URL: << parameters.jira-url >> JIRA_TRANS_ID: << parameters.jira-transition-id >> JIRA_AUTH_TOKEN: "$<< parameters.jira-auth >>" + JIRA_PROJECT: << parameters.jira-project >> command: <> diff --git a/src/examples/use_acsf_jobs.yml b/src/examples/use_acsf_jobs.yml index 4304c05..1a40bac 100755 --- a/src/examples/use_acsf_jobs.yml +++ b/src/examples/use_acsf_jobs.yml @@ -20,6 +20,10 @@ usage: acsf-env: "test" acsf-deploy-type: "code, db" slack-channel: "@your_channel" + jira-transition-id: "3" + jira-url: "https://your.jira.url" + jira-project: "ABC" img-version: "latest" + mk_message: "## Deployment started ✨" requires: - approve-deployment diff --git a/src/jobs/deploy-tag.yml b/src/jobs/deploy-tag.yml index 54ff600..be39404 100755 --- a/src/jobs/deploy-tag.yml +++ b/src/jobs/deploy-tag.yml @@ -40,6 +40,10 @@ parameters: default: "" type: string description: 'The Jira Cloud URL' + jira-project: + default: "" + type: string + description: 'The Jira Project key for which we should transition tickets.' tag: default: $CIRCLE_TAG type: string @@ -50,6 +54,13 @@ parameters: Pick a specific mobomo/drupalstand-ci image variant: https://hub.docker.com/r/mobomo/drupalstand-ci/tags type: string + mk_message: + default: "## Deployment started ✨" + type: string + description: > + The message to display on Slack channel when the + deployment starts. It must be a string and supports Markdown. + Do not include the "```" quotes. steps: - checkout - compare-tags: @@ -73,6 +84,7 @@ steps: acsf-site: << parameters.acsf-site >> jira-transition-id: << parameters.jira-transition-id >> jira-url: << parameters.jira-url >> + jira-project: << parameters.jira-project >> - slack/notify: event: pass channel: << parameters.slack-channel >> @@ -91,7 +103,7 @@ steps: "type": "section", "text": { "type": "mrkdwn", - "text": "``` _______________________\n/ Deployment completed \\\n\\ Find info below me /\n -----------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||```" + "text": "```<< parameters.mk_message >>```" } }, { @@ -113,6 +125,10 @@ steps: "type": "mrkdwn", "text": "*Tag:*\n<< parameters.tag >>" }, + { + "type": "mrkdwn", + "text": "*Jira Project:*\n$JIRA_PROJECT" + }, { "type": "mrkdwn", "text": "*Tickets:*\n$JIRA_ISSUES" @@ -137,20 +153,6 @@ steps: } ] }, - { - "type": "context", - "elements": [ - { - "type": "image", - "image_url": "https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg", - "alt_text": "cute cat" - }, - { - "type": "mrkdwn", - "text": "*cat* approved this message :heavy_check_mark:" - } - ] - }, { "type": "divider" } diff --git a/src/scripts/jira-transition.sh b/src/scripts/jira-transition.sh index 1c0de93..aed3b5c 100644 --- a/src/scripts/jira-transition.sh +++ b/src/scripts/jira-transition.sh @@ -4,6 +4,7 @@ set -eu # VARS EVAL. TAG_TO_DEPLOY=$(eval echo "$TAG") JIRA_TOKEN=$(eval echo "$JIRA_AUTH_TOKEN") +#JIRA_PROJECT=$(eval echo "$JIRA_PROJECT") # Determine acquia environment, since acsf user/keys are per env. get-acquia-key() { @@ -38,11 +39,11 @@ get-current-tag() { CURRENT_TAG=$(get-current-tag) echo "Current Tag on ${ACSF_ENV}: $CURRENT_TAG" -# With the the current tag, get a list of issues IDs that were committed between current and latest. +# With the the current tag, get a list of issues IDs that were committed between current and latest. Filtering by Jira Project Key. get-jira-issues() { local JIRA_ISSUES if [ -n "${CURRENT_TAG}" ]; then - JIRA_ISSUES=$(git log "${CURRENT_TAG}".."${TAG_TO_DEPLOY}" | grep -e '[A-Z]\+-[0-9]\+' -o | sort -u | tr '\n' ',' | sed '$s/,$/\n/') + JIRA_ISSUES=$(git log "${CURRENT_TAG}".."${TAG_TO_DEPLOY}" | grep -e "${JIRA_PROJECT}-[0-9]\+" -o | sort -u | tr '\n' ',' | sed '$s/,$/\n/') echo "$JIRA_ISSUES" else echo "We were not able to get current tag deployed to ACSF Env. Please check the 'acsf-' parameters are correctly set." @@ -55,6 +56,7 @@ transition-issues() { if [ -n "${JIRA_ISSUES}" ]; then echo "Included tickets between ${CURRENT_TAG} and ${TAG_TO_DEPLOY}: ${JIRA_ISSUES}" echo "export JIRA_ISSUES=$(get-jira-issues)" >> "$BASH_ENV" + echo "export JIRA_PROJECT=${JIRA_PROJECT}" >> "$BASH_ENV" for issue in ${JIRA_ISSUES//,/ } do echo "Transitioning $issue..."