Gather all the Jira Tickets in the lastest Bamboo Release using a Bamboo Script Task
Asked by Patrick Laubner:

Hello everyone,

I'm trying to automate the post release process inside of Bamboo, I have a the following structure in my build plan (upstream):

* Build Project
  * Plan
    * Default Stage
      * Job Build JAR
        * Task Git Checkout
        * Task Maven
        * Task create Git Tag in repo

After building my project I have a successful build with i.E. #14 and the tag 'v5.10.4.1' in ButBucket (Git).

Following this I created a Deployment Project (downstream) that has these script tasks:

* Create fixVersion in Jira
* Gather all the Jira Tickets in the lastest Bamboo Release
* Add all Bamboo Release Tickets to Jira Release

The steps use *curl* in some form or another and the REST API either from Jira or Bamboo, **Step 1** works with any problems as long as the **fixVersion** hasn't been created in Jira previously.

For **Step 2** I did a test from my workstation with success using this command to get the issues and save them as a text file for **Step 3** afterwards:

```

curl -X GET --user ${bamboo.user}:${bamboo.password} -H 'X-Atlassian-Token: no-check' "https://server-name/rest/api/latest/result/${bamboo.buildResultKey}.json?expand=jiraIssues" -o >(grep -o -E '"(Ticket-KEY)-\d*"' | tr -d '"' > /tmp/issueKeys.txt) && cat /tmp/issueKeys.txt

```

I tried doing this as a Script Task during my deployment as either inline or file based, this is my script:

```

#!/bin/bash

# Variables: ${bamboo.user}:${bamboo.password}; ${bamboo.buildResultKey}
# Gather all the Jira Tickets in the lastest Bamboo Release as the second step

echo "==> Gather all the Jira Tickets in the lastest Bamboo Release: yes"

curl -X GET --user ${bamboo.user}:${bamboo.password} -H 'X-Atlassian-Token: no-check' "https://server-name/rest/api/latest/result/${bamboo.buildResultKey}.json?expand=jiraIssues" -o >(grep -o -E '"(Ticket-KEY)-\d*"' | tr -d '"' > /tmp/issueKeys.txt)

echo "==> The following Jira Tickets from the lastest Bamboo Release have been gathered"

# for debugging run this to verfiy the results in the Bamboo deployment logs
cd /tmp/ && ls -la && cat issueKeys.txt && nl issueKeys.txt

```

I ran into the following problems:

* Using https in the curl command on Bamboo itself will log: **curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number**
* Using http in the curl command on Bamboo itself will log a **404**:

```


13-Dec.-2023 14:05:53 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
13-Dec.-2023 14:05:53 <html><head>
13-Dec.-2023 14:05:53 <title>404 Not Found</title>
13-Dec.-2023 14:05:53 </head><body>
13-Dec.-2023 14:05:53 <h1>Not Found</h1>
13-Dec.-2023 14:05:53 <p>The requested URL was not found on this server.</p>
13-Dec.-2023 14:05:53 <hr>

```

It seems it is not possible to curl the Bamboo REST API from inside of Bamboo it's self but it should be possible, I found this in the Atlassian documentation:

```

curl -u <ADMIN_USERNAME>:<PASSWORD> <BAMBOO_URL>/build/admin/ajax/getDashboardSummary.action
```

Maybe someone has solved this already but I can't find a thread or documentation. Many thanks for help or ideas!


Answers:
author: alok m
body: Your issue with using **curl** to access the Bamboo REST API from within Bamboo itself appears to involve a couple of different problems: SSL issues and incorrect URL handling. Let's address each issue and propose a solution.

**SSL Issue**

The error message **curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number** suggests a mismatch in the SSL protocol between the **curl** client and the server. This can be caused by an outdated **curl** or OpenSSL library on the Bamboo server or by specific server configurations.

Possible Solutions:

1. **Update curl and OpenSSL** : Ensure that both **curl** and OpenSSL are up to date on the Bamboo server. This can often resolve SSL version mismatch issues.
2. **Specify SSL Version** : You can explicitly specify the SSL version **curl** should use with the **--sslv3** , **--tlsv1.0** , **--tlsv1.1** , **--tlsv1.2** , or **--tlsv1.3** options, depending on what the server supports. Be cautious with this approach, as using older versions of SSL/TLS can introduce security vulnerabilities.
3. **Disable SSL Verification** : As a last resort and only for internal, secure networks, you can disable SSL certificate verification in **curl** with the **-k** or **--insecure** option. **This is not recommended for production environments** due to security risks.

**HTTP 404 Error**

Receiving a 404 error with the HTTP URL might be due to incorrect API endpoint specification or server configuration that does not route HTTP traffic correctly.

Check the API Endpoint:

Ensure that the API endpoint URL is correct. It's worth double-checking the base URL and the API path. Sometimes, path issues or typos can lead to 404 errors.

**Script Adjustments**

Given the issues you're facing, here are some adjustments and considerations for your script:

1. **Debugging SSL** :
   * Initially, try running **curl** with the **-v** (verbose) flag to get more insight into the SSL negotiation process.
   * Test the SSL version specification, e.g., **curl --tlsv1.2 ...**, to see if specifying the version resolves the issue.
2. **Ensure Correct API Endpoint** :
   * Verify the API endpoint URL directly via a browser or Postman to ensure it's correct and accessible.
3. **Use Internal Hostname** :
   * If the SSL issue persists, and you're accessing an internal service, consider using the internal hostname (without SSL) if security policies permit. Ensure the URL and port are correct for internal access.
4. **Script Modification**:

bash

#!/bin/bash # Use -k for debugging purposes only; remove in production curl -k -v -X GET --user ${bamboo.user}:${bamboo.password} -H 'X-Atlassian-Token: no-check' "<https://server-name/rest/api/latest/result/${bamboo.buildResultKey}.json?expand=jiraIssues>" \| grep -o -E '"(Ticket-KEY)-\\d\*"' \| tr -d '"' \> /tmp/issueKeys.txt echo "==\> The following Jira Tickets from the latest Bamboo Release have been gathered" cat /tmp/issueKeys.txt

1. **Environment Variables** :
   * Make sure **bamboo.user** , **bamboo.password** , and **bamboo.buildResultKey** are correctly set as environment variables in your Bamboo plan or deployment project.
2. **Alternative Tools** : If **curl** continues to cause issues, consider alternative command-line tools like **wget** , or scripting languages like Python with the **requests** library, which may offer more flexibility and better error handling.

Lastly, always consult the latest Atlassian documentation and consider reaching out to Atlassian support or community forums if the problem persists. Custom situations like this can sometimes involve nuances specific to your environment or version of the tools you're using.


Tags: jira

rest-api