Comment Mentions#
Execute JavaScript code directly from Jira comments by mentioning @automan.
Overview#
Comment Mentions provide a quick way to run JavaScript code without creating definitions or configuring triggers. Simply mention @automan in a comment and include your code in a code block - Automan will execute it and reply with the results.
This feature is useful for:
- Quick one-off scripts and queries
- Debugging and exploring data
- Ad-hoc automations
- Learning and experimentation
How It Works#
- Add a comment to any Jira work item
- Mention
@automananywhere in the comment - Include one or more code blocks with JavaScript code
- Automan executes each code block and replies with the results
Usage#
Basic Example#
Add a comment like this:
@automan
const response = await requestJira(route`/rest/api/3/myself`); const user = await response.json(); user.displayName;
Automan will reply with a comment showing the executed code and result:
@yourname
const response = await requestJira(route`/rest/api/3/myself`); const user = await response.json(); user.displayName;=> "John Doe"
Multiple Code Blocks#
You can include multiple code blocks in a single comment. Each will be executed separately:
@automan
Get issue details:
const response = await requestJira(route`/rest/api/3/issue/${event.issue.key}`); const issue = await response.json(); issue.fields.summary;Count comments:
const response = await requestJira(route`/rest/api/3/issue/${event.issue.key}/comment`); const comments = await response.json(); comments.total;
Context Variables#
When your code executes, the event object contains the comment event data:
{
eventType: "avi:jira:commented:issue",
// The issue where the comment was added
issue: {
id: "10001",
key: "PROJ-123"
},
// The comment that triggered the execution
comment: {
id: "10050",
author: {
accountId: "5a0000000000000000000001",
displayName: "John Doe"
},
body: { ... }
}
}Accessing Issue Data#
Use event.issue.key to reference the current issue:
// Get full issue details
const response = await requestJira(route`/rest/api/3/issue/${event.issue.key}`);
const issue = await response.json();
console.log("Summary:", issue.fields.summary);
console.log("Status:", issue.fields.status.name);
console.log("Assignee:", issue.fields.assignee?.displayName);Examples#
Get Issue Summary#
const response = await requestJira(route`/rest/api/3/issue/${event.issue.key}`);
const issue = await response.json();
issue.fields.summary;List Subtasks#
const response = await requestJira(route`/rest/api/3/issue/${event.issue.key}`);
const issue = await response.json();
const subtasks = issue.fields.subtasks || [];
subtasks.map(s => `${s.key}: ${s.fields.summary}`);Search Related Issues#
const response = await requestJira(route`/rest/api/3/issue/${event.issue.key}`);
const issue = await response.json();
const projectKey = issue.fields.project.key;
const jql = `project = "${projectKey}" AND status = "In Progress"`;
const searchResponse = await requestJira(
route`/rest/api/3/search/jql?jql=${encodeURIComponent(jql)}&maxResults=5`
);
const result = await searchResponse.json();
result.issues.map(i => i.key);Get Current User Info#
const response = await requestJira(route`/rest/api/3/myself`);
const user = await response.json();
({ name: user.displayName, email: user.emailAddress });Update Issue Field#
await requestJira(
route`/rest/api/3/issue/${event.issue.key}`,
{
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
fields: {
labels: ["reviewed"]
}
})
}
);
"Label added!";Add a Comment#
await requestJira(
route`/rest/api/3/issue/${event.issue.key}/comment`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
body: {
type: "doc",
version: 1,
content: [{
type: "paragraph",
content: [{ type: "text", text: "This comment was added by script!" }]
}]
}
})
}
);
"Comment added!";Output Format#
Console Logs#
Use console.log() to output debug information:
console.log("Starting script...");
console.log("Issue key:", event.issue.key);
"Done";Output:
Starting script...
Issue key: PROJ-123
=> "Done"Return Values#
The last expression in your code is returned as the result:
const a = 1;
const b = 2;
a + b; // This is returned
Output:
=> 3Objects and Arrays#
Objects and arrays are formatted as JSON:
({ name: "John", age: 30 });Output:
=> {
"name": "John",
"age": 30
}Errors#
If your code throws an error, it’s shown in the output:
throw new Error("Something went wrong");Output:
Error: Something went wrongLimitations#
User Context#
Comment mentions execute as the commenting user, not as the app. This means:
- Created issues will have the commenting user as reporter
- API requests are made with the commenting user’s permissions
- Operations will fail if the user lacks the required permissions
Execution Time#
Scripts have a maximum execution time of 20 seconds. Long-running scripts will be terminated.
No Environment Variables#
For security, environment variables are not accessible in comment mentions. Use Script Definitions with proper triggers for scripts that need secrets.
Security Considerations#
- Comment mentions execute code from any user who can comment on issues
- Scripts run with the commenting user’s permissions
- Users can only perform actions they would normally be authorized to do
- Consider who has comment access to your projects
Troubleshooting#
Script Not Executing#
- Ensure
@automanis mentioned (not just typed as text) - Use proper code block formatting (triple backticks)
- Check that Automan is installed and enabled
No Response Comment#
- Check the Automan Executions tab for errors
- Verify the code block contains valid JavaScript
- Ensure the app has permission to comment on the issue
Permission Errors#
- Comment mentions run as the commenting user
- Operations will fail if the user lacks the required permissions
- Verify the commenting user has access to the resources being accessed