|
| 1 | +#!/bin/bash |
| 2 | +# 70_publish_outcomes.sh |
| 3 | +# Post a completion comment to the Jira issue associated with this repository. |
| 4 | +# Ticket resolved in order: $jiraticket env var → config.yml → openICPSR directory detection. |
| 5 | +# |
| 6 | +# Usage: 70_publish_outcomes.sh [pipeline-name] |
| 7 | +# pipeline-name Optional. Name of the Bitbucket custom pipeline (e.g., "1-populate-from-icpsr"). |
| 8 | +# No Bitbucket built-in variable exposes this; pass it explicitly from the pipeline. |
| 9 | + |
| 10 | +_pipeline="${1:-}" |
| 11 | + |
| 12 | +# Detect Python command |
| 13 | +if command -v python3.12 &>/dev/null; then |
| 14 | + PYTHON_CMD="python3.12" |
| 15 | +elif command -v python3 &>/dev/null; then |
| 16 | + PYTHON_CMD="python3" |
| 17 | +else |
| 18 | + echo "70_publish_outcomes: no Python 3 found, skipping Jira notification" |
| 19 | + exit 0 |
| 20 | +fi |
| 21 | + |
| 22 | +_jira="${jiraticket:-}" |
| 23 | +echo "70_publish_outcomes: jiraticket from environment: '${_jira}'" |
| 24 | + |
| 25 | +# Fall back to config.yml |
| 26 | +if [ -z "$_jira" ]; then |
| 27 | + if [ -f config.yml ] && [ -f tools/parse_yaml.sh ]; then |
| 28 | + . ./tools/parse_yaml.sh |
| 29 | + _jira=$(parse_yaml config.yml | grep '^jiraticket=' | sed 's/jiraticket=//;s/"//g') |
| 30 | + echo "70_publish_outcomes: jiraticket from config.yml: '${_jira}'" |
| 31 | + else |
| 32 | + echo "70_publish_outcomes: config.yml or parse_yaml.sh not found, skipping config.yml lookup" |
| 33 | + fi |
| 34 | +fi |
| 35 | + |
| 36 | +# Fall back to directory-based lookup |
| 37 | +if [ -z "$_jira" ]; then |
| 38 | + _icpsr=$(find . -maxdepth 1 -mindepth 1 -type d -name '[123][0-9][0-9][0-9][0-9][0-9]' 2>/dev/null \ |
| 39 | + | head -1 | xargs -I{} basename {} 2>/dev/null || true) |
| 40 | + if [ -n "$_icpsr" ]; then |
| 41 | + echo "70_publish_outcomes: detected openICPSR directory '${_icpsr}', looking up Jira ticket" |
| 42 | + _jira=$($PYTHON_CMD tools/jira_find_task_by_icpsr.py "$_icpsr" 2>&1) || true |
| 43 | + echo "70_publish_outcomes: jiraticket from lookup: '${_jira}'" |
| 44 | + else |
| 45 | + echo "70_publish_outcomes: no openICPSR directory found" |
| 46 | + fi |
| 47 | +fi |
| 48 | + |
| 49 | +if [ -n "$_jira" ]; then |
| 50 | + _url="https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pipelines/results/$BITBUCKET_BUILD_NUMBER" |
| 51 | + echo "70_publish_outcomes: posting completion comment to ${_jira}" |
| 52 | + $PYTHON_CMD tools/jira_add_comment.py "$_jira" \ |
| 53 | + "Bitbucket Pipeline ${_pipeline} completed. Build [#$BITBUCKET_BUILD_NUMBER|$_url]." || true |
| 54 | +else |
| 55 | + echo "70_publish_outcomes: no Jira ticket found, skipping comment" |
| 56 | +fi |
| 57 | + |
| 58 | +exit 0 |
0 commit comments