Dynamic Pipeline and Bitbucket API Integration leading to erratic pipeline behavior

Bhrugu Rajput December 6, 2024

Use-case: We are trying to create a workflow where if a PR doesn't exist, a default step is triggered which would create a PR for us (this works just fine). And if a PR does exist, only the PR step is triggered (not the PR step and other steps). 

PR Workflow: If a PR does exist for a commit (we are checking this using bitbucket API), we want to only trigger the pr pipeline, not the branch pipeline or the default step pipeline, etc. 

Dynamic Pipelines: We are calling the bitbucket API, doing proper async calls and awaits. The particular API in question is: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-commit-commit-pullrequests-get.

This also works just fine, we get a 200, and it returns list of values if a PR exists and returns an empty list if a PR doesn't exist. 

Problem: We do an if on the values returned by the API (awaited and asynced) to check whether values is empty or not. If values is not empty (PR exists), we delete the pipeline_configuration's default and branch pipeline, this should just leave the PR pipeline configuration. 

Expected Behaviour: The pipeline 'default' or 'branch' step should not be triggered when a PR does exist, and only the PR pipeline should be ran and triggered as that is the only pipeline in question. 

Current Behaviour: Our pipeline sometimes does execute the expected behaviour and sometimes it doesn't. We are not sure what is causing this, our guess is some concurrency issue or something to do with Forge Backend. 

Forge Tunnel Logs: Forge tunnel outputs the correct logs / configuration for the expected behaviour on every run, but this is not reflected in the bitbucket pipeline runs page. 

Notes: If we remove the if-statement, then we get the expected behaviour, however, then of course our workflow for triggering the default pipeline to create a PR goes out of the window. We tried console logs before and after the if statement, and it is working as expected as reflected by the correct Forge Tunnel Logs. 

Problem piece 
```

if (response.values.length === 1) {
    delete request.pipelines_configuration.pipelines.default;
    delete request.pipelines_configuration.pipelines.branches;
    console.log(`Updated request: ${JSON.stringify(request, null, 4)}`);
    return { pipelines_configuration: request.pipelines_configuration };
}
```

Workarounds we haven't tried yet: Instead of deleting configurations when a PR does exist, (the negative), we create a configuration which will create a default step to create a PR, if a PR does not exist.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events