To send messages to Jira, you must first add a Jira Integration to Pipelines. The Jira integration securely holds your access credentials in Pipelines' encrypted vault, so that this information is not viewable in the text of your Pipelines DSL file.
To add a Jira integration, follow the procedures in Managing Pipelines Integrations.
For example, to add a Jira integration called myJira
, you might enter the following:
The User Name and Token fields provide the necessary credentials to authenticate access from Pipelines:
To create a new Jira issue (ticket) from step in a pipeline:
integrations
section of the step.You will typically send the notification to Jira in an onFailure
portion of the step's execution
block.
execution: onExecute: ... onFailure: - send_notification myJira --project-id "DEMO" --type "Bug" --summary "Build Failed: $pipeline_name:$run_number" --description "Step $step_name" Failed" |
The project-id must specify a key for a project that has already been created in Jira. If Jira receives a request to create a ticket for a project that doesn't exist, Jira will ignore the request. |
If your pipeline will have multiple failure points to create a Jira issue, you might choose to define common values for options such as project-id and type in environment variables for those options. The send_notification
utility function for a Jira integration will automatically use any of these environment variables when they are defined:
Environment Variable | Option | Description |
---|---|---|
NOTIFY_PROJECT_ID | --project-id | the project key of the project to associate the new issue with |
NOTIFY_TYPE | --type | the |
NOTIFY_SUMMARY | --summary | a string for the new issue's Summary field (it's title) |
NOTIFY_DESCRIPTION | --description | a string for the new issue's Description field |
NOTIFY_ATTACH_FILE | --attach-file | a path to a file to attach to the issue |
You can define any of these environment variables in the pipeline's configuration
block using the environmentVariables
tag, so that they will be available to all steps in the pipeline. You can also, if needed, specify environmentVariables
in the step's configuration
block to override their value for the span of that step's execution.
The following example pipeline demonstrates the use of the send_notification
utility function to create a Jira issue (ticket).
The example Pipelines DSL performs the following:
send_notification
utility function to create the JIra ticket. The command line:resources: - name: my_repo type: GitRepo configuration: gitProvider: MyGithub path: myrepo/myproject pipelines: - name: jira_ticket_example configuration: environmentVariables: readOnly: NOTIFY_PROJECT_ID: "DEMO" # Jira project key for all tickets we create NOTIFY_TYPE: "Bug" # Jira issue type for all tickets we create steps: ### with jira for log attachment - name: BuildSample type: MvnBuild configuration: sourceLocation: artifactory-maven-plugin-example configFileLocation: . configFileName: config mvnCommand: "install -P release --log-file ${step_tmp_dir}/log.txt" inputResources: - name: my_repo integrations: - name: myArtifactory - name: myJira execution: onFailure: - send_notification myJira --attach-file "$step_tmp_dir/log.txt" --description "Failure occured in $pipeline_name - $step_name" --summary "$step_name has failed" |