Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

jira_add_comment.py - Post comments to Jira issues

Description

Posts a comment to a Jira issue using the Jira API. Supports Jira wiki markup formatting in comments. Designed to run in automated pipelines and in SLURM batch jobs, and fails gracefully if credentials are not available.

With --partb, the comment is redirected from the main ticket to the ticket’s “Part B ...” sub-task, so that a caller only ever needs to know the main ticket.

Usage

python3 tools/jira_add_comment.py [options] <issue-key|auto> [comment]

Arguments

Options

OptionEffect
--partbPost to the “Part B ...” sub-task of the issue instead of the issue itself (see Part B resolution)
--status STATUSPrepend a standard status line. started → 🚀, completed → ✅, failed → ❌; any other value is used verbatim with ℹ️
--exit-code NUse with --status: a non-zero N turns completed into failed and appends the exit code. Lets one call report both success and failure from a shell trap
--label TEXTWhat --status is talking about (default: Job), e.g. SLURM job main.do. Ignored in favour of SLURM job <id> <name> when --slurm is given inside a real job
--slurmFold the SLURM job ID, job name and submit directory into the status line, e.g. ✅ SLURM job 590340 main.do completed (directory: /path/to/submit/dir). Without --status, the same context is added as a line of its own. Silently omitted when not running inside a SLURM job
--env-file PATHRead credentials from PATH in addition to the default locations. May be repeated
--dry-runResolve the target issue and print the comment that would be posted, without posting it
--End of options; everything after it is positional
-h, --helpShow usage

Examples

# Simple comment on the main ticket
python3 tools/jira_add_comment.py AEAREP-8885 "Pipeline completed successfully"

# With Jira markup
python3 tools/jira_add_comment.py aearep-1234 "*Pipeline Status:* ✅ Complete"

# Comment on the Part B sub-task of AEAREP-8885, whatever its key is
python3 tools/jira_add_comment.py --partb AEAREP-8885 "Started the Stata run"

# Start/stop notification from a SLURM job, ticket read from config.yml.
# --slurm supplies the "SLURM job <id> <name>" label itself, so --label is
# not needed inside a real job.
python3 tools/jira_add_comment.py --partb --slurm --status started -- auto
python3 tools/jira_add_comment.py --partb --slurm --status completed \
    --exit-code "$rc" -- auto

# Check what would be posted, and where, without posting
python3 tools/jira_add_comment.py --partb --dry-run AEAREP-8885 "test"

Requirements

Credentials

These are looked up in the following order; the process environment always wins, and each file may supply whatever is still missing:

  1. the process environment

  2. any --env-file PATH given, in order

  3. ./.env

  4. ./.envvars

  5. ~/.envvars

  6. ~/envvars.txt

  7. ~/.env

Files are parsed as simple KEY=value lines. A leading export and surrounding quotes are stripped; # comments and blank lines are ignored. This is the same format used by source ~/.envvars, so one file can serve both purposes.

Ticket resolution

When the issue key is the literal string auto, the script resolves the ticket from, in order:

  1. the $jiraticket (or $JIRATICKET) environment variable

  2. the jiraticket: line of the nearest config.yml, searched from $SLURM_SUBMIT_DIR (or the current directory) upward through four parent directories

If nothing resolves, a warning is printed and no comment is posted.

Part B resolution

With --partb, the script looks for the sub-task that tracks Part B work:

A sub-task matches when its issue type starts with “Part B” - in AEAREP that is Part B processing: run code or complete report. Only if no sub-task matches by issue type does the script fall back to matching sub-tasks whose summary contains “Part B”, which catches the SIVACOR-style sub-tasks that carry a different issue type (e.g. Author-generated reproducibility check with summary Prepare Part B (SIVACOR)). If several sub-tasks match, the highest-numbered one is used.

If no Part B sub-task can be found, the script prints a warning and comments on the main ticket instead, so a job never loses its notification.

Behavior

This design allows the script to be used in pipelines and batch jobs where Jira access may not always be available without causing failures.

See Also