How can I pass the name of a Jira ticket created with Python code back to Jenkinsfile?

23 views Asked by At

so I have a Jenkinsfile step that looks something like this:

script {
   
        def jira_raise_project = 'TEST'  // Dictates which Board you raise Jira Ticket to
        def jira_raise_title = 'Updates requirements for JS deployment'
        def entrypoint = "${env.WORKSPACE}/release-tools.sh"
        def diff_path = "$WORKSPACE/requirements_diff.txt"

        writeFile file: entrypoint, text: """\
           #!/usr/bin/env bash
           set -ex
           #pip install release-tools  
           pushd $WORKSPACE/release-tools
           pip install -e .
           releasetools create-diff-report '$jira_raise_project' '$jira_raise_title' '$diff_path'
           popd""".stripIndent()
        withCredentials([
            string(credentialsId: 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxff1819', variable: 'GITHUB_TOKEN'),
            usernamePassword(credentialsId: 'jira-system-user', usernameVariable: 'JIRA_USERNAME', passwordVariable: 'JIRA_PASSWORD'),
   string(credentialsId: 'blackduck-token', variable: 'BLACKDUCK_TOKEN')
        ]) {
            sh "sudo chmod +x $entrypoint && \
            docker pull xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/compute-env-build-agent:latest && \
            docker run -v ${env.WORKSPACE}:${env.WORKSPACE} -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
            -e WORKSPACE=${env.WORKSPACE} -e GITHUB_TOKEN=$GITHUB_TOKEN -e JIRA_SERVER=$JIRA_SERVER \
            -e JIRA_USERNAME=$JIRA_USERNAME -e JIRA_PASSWORD=$JIRA_PASSWORD -e BLACKDUCK_TOKEN=$BLACKDUCK_TOKEN \
            --workdir=${env.WORKSPACE} --entrypoint=$entrypoint \
            xxxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/compute-env-build-agent:latest"
        }
    }

What the above code does, specifically,

releasetools create-diff-report '$jira_raise_project' '$jira_raise_title' '$diff_path'

Is a command line options that I create in a repo called releasetools

And in that repo it is using python argparse to create a Jira ticket with Python code.

I need to be able to pass the name of the Jira ticket back to the Jenkinsfile above, is this possible?

Towards the end of my build I can see the Jira ticket name (see the second last time):

[2024-02-07T18:08:35.840Z] pyopenssl 23.2.0 requires cryptography!=40.0.0,!=40.0.1,<42,>=38.0.0, but you have cryptography 37.0.2 which is incompatible.

[2024-02-07T18:08:35.840Z] Successfully installed blackduck-1.0.7 release-tools-9999.9.9.9 boto3-1.24.9 botocore-1.27.9 certifi-2022.5.18.1 cffi-1.15.0 charset-normalizer-2.0.12 cryptography-37.0.2 defusedxml-0.7.1 deprecated-1.2.13 idna-3.3 importlib-metadata-4.11.4 jeepney-0.8.0 jinja2-3.1.2 jira-3.2.0 jmespath-1.0.0 keyring-23.6.0 markupsafe-2.1.1 oauthlib-3.2.0 packaging-21.3 pkginfo-1.8.3 pygithub-1.55 pyjwt-2.4.0 pynacl-1.5.0 pyparsing-3.0.9 python-dateutil-2.8.2 pyyaml-6.0 requests-2.28.0 requests-oauthlib-1.3.1 requests-toolbelt-0.9.1 s3transfer-0.6.0 secretstorage-3.3.2 six-1.16.0 typing-extensions-4.2.0 urllib3-1.26.9 wrapt-1.14.1 zipp-3.8.0

[2024-02-07T18:08:36.401Z] + releasetools create-diff-report TEST 'Updates requirements for JS deployment' /home/ec2-user/jenkins/workspace/js_PR-4341/requirements_diff.txt

[2024-02-07T18:08:40.619Z] Ticket for TEST-504: https://xxxxtech.atlassian.net/browse/TEST-504

[2024-02-07T18:08:40.620Z] + popd
0

There are 0 answers