Cloud customer?
Start for Free >
Upgrade in MyJFrog >
What's New in Cloud >

Search





Overview

Pipelines provides facilities to create a new issue (also called a ticket) for a project repository in Atlassian Jira Cloud or Server from an executing pipeline.

You may wish to create a new issue (ticket) in a Jira project repository when:

  • Your build fails to complete
  • Your pipeline runs automated tests and you need to create a new Jira issue when the test fails

No additional plugin or extension needs to be installed to use this facility in Pipelines. It makes use of a built-in utility function than can be invoked from any step in a pipeline.


Page Contents


Adding a Jira Integration

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:

  • User Name: The user account represented by User Name must have  permissions to access the Jira project where issues are to be created.
  • Jira Cloud Token: When integrating with Jira Cloud, you must provide the  Jira API token for the Jira user account in the Token field.
  • Jira Server Password: When integrating with Jira Server, you must provide the user account password in the Token field (Jira Server does not support API tokens).



Creating a Jira Issue

To create a new Jira issue (ticket) from step in a pipeline:

  1. Declare the Jira integration in the integrations section of the step.
  2. Use the send_notification utiliity function to notify the Jira integration to create an issue ticket.

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.

Using Environment Variables

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 VariableOptionDescription
NOTIFY_PROJECT_ID--project-idthe project key of the project to associate the new issue with
NOTIFY_TYPE --type

the issue type for the new issue (e.g., "Bug", "Task", etc.).

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.

Example

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:

  • Sets environment variables for the project-id and type options
  • Performs a MvnBuild native step, which produces a log file.
  • On failure, uses the send_notification utility function to create the JIra ticket. The command line:
    • Relies on the environment variables for the project-id and type options
    • Attaches the log file produced by Maven to the Jira issue
    • Specifies the summary and description options using standard environment variables 


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" 
  • No labels
Copyright © 2021 JFrog Ltd.