Is it possible to access the variables used for a custom pipeline via BitBucket API?
Asked by Brenainn Moushall:

I'm running custom pipelines that take variables, and I'd like to be able to retrieve the {key: val} pairs for the variables when fetching a pipeline from the API.

I can see that there's endpoints for repository, workspace and environment variables, but I need the key-value pairs specified when the pipeline is launched.

I've looked through the pipeline response from

```
GET /2.0/repositories/{workspace}/{repo_slug}/pipelines/{pipeline_uuid}
```

and step response from

```
GET /2.0/repositories/{workspace}/{repo_slug}/pipelines/{pipeline_uuid}/steps/{step_uuid}
```

and they don't seem to be included. Pipeline response does have a 'has_variables' boolean, but I'm not sure if this refers to the custom pipeline variables or other types.

Just want to know if this is possible, as I can work around it otherwise.

Cheers!


Answers:
author: Theodora Boudale
body: Hi [@Brenainn Moushall](/t5/user/viewprofilepage/user-id/1580744),

I'm afraid that this is not possible with the pipeline or step endpoint.

The values of these variables are visible in the Pipelines log, in the "Build setup", which can be retrieved with the endpoint

```
GET /2.0/repositories/{workspace}/{repo_slug}/pipelines/{pipeline_uuid}/steps/{step_uuid}/log
```

You would then need to parse the log to get the value of each variable.

Kind regards,  
Theodora

comments: author: Brenainn Moushall
body: No problem, thanks for letting me know


author: Theodora Boudale
body: You are very welcome, please feel free to reach out if you ever need anything else!

Kind regards,  
Theodora


author: Julien Bras
body: Hi,

We are in 2024, is-it still the only option to get access to the variables set during the pipeline launch via API?

Because the API documentation show us a nice \`variables\` prop in the \`list pipelines\` operation ;)

<https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-get>

```
{
"page": 102,
"values": [
{
"type": "<string>",
"uuid": "<string>",
"build_number": 33,
"creator": {
"type": "<string>"
},
"repository": {
"type": "<string>"
},
"target": {
"type": "<string>"
},
"trigger": {
"type": "<string>"
},
"state": {
"type": "<string>"
},
"variables": [
{
"type": "<string>"
}
],
```

comments: author: Theodora Boudale
body: Hi Julien,

The option mentioned in my answer above is the only one at the moment.

The "variables" property is not returned with the pipeline endpoint, I have reached out to my team internally to remove this from our docs in order to avoid confusion.

I also created a feature request for returning custom pipelines' variables and their values via API:

* <https://jira.atlassian.com/browse/BCLOUD-23359>

You can add your vote to it (by selecting the **Vote for this issue** link) to express your interest and you can also add yourself as a watcher (by selecting the **Start watching this issue** link) if you'd like to be notified via email on updates.

Kind regards,  
Theodora


author: Julien Bras
body: hi, thanks for the update and the documentation clarification! I will check the feature request creation to vote for it!

Thanks!


Tags: bitbucket-cloud

bitbucket-pipelines

cloud