Create a Jira Issue as part of a Pipeline

JFrog Pipelines Documentation

ft:sourceType
Paligo

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"

Note

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.

Use 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 Variable

Option

Description

NOTIFY_PROJECT_ID

--project-id

the 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"