Trigger pipeline in another repo
Asked by Brett Steinicke:

Trying to trigger a pipeline in another repo

The triggering repo has this for its bitbucket-pipelines.yml

options:  
docker: true  
pipelines:  
pull-requests:  
'\*\*': #trigger pipeline in gemm_fw  
- step:  
script:  
- pipe: atlassian/trigger-pipeline:5.0.1  
variables:  
BITBUCKET_USERNAME: 'bsteinic'  
BITBUCKET_APP_PASSWORD: 'app-password generated'  
REPOSITORY: 'gemm_fw'  
REF_TYPE: 'branch'  
REF_NAME: 'master'  
#CUSTOM_PIPELINE_NAME: 'pull-requests'  
# \[{  
# "key": "BITBUCKET_BRANCH",  
# "value": "${BITBUCKET_BRANCH}"  
# }\]  
DEBUG: 'true'  
WAIT: 'true'

Fails with the following:

DEBUG: Starting new HTTPS connection (1): bitbucket.org:443  
DEBUG: <https://bitbucket.org:443> "GET /bitbucketpipelines/official-pipes/raw/master/pipes.prod.json HTTP/1.1" 200 None  
DEBUG: Starting new HTTPS connection (1): api.bitbucket.org:443  
DEBUG: <https://api.bitbucket.org:443> "POST /2.0/repositories/tdwilliamson_ee/gemm_fw/pipelines/ HTTP/1.1" 400 160  
? Error: {"error": {"message": "Bad request", "detail": "bitbucket-pipelines.yml not found.", "data": {"key": "result-service.pipeline.yml-not-found", "arguments": {}}}}


Answers:
author: Igor Stoyanov
body: [@Brett Steinicke](/t5/user/viewprofilepage/user-id/3797200) hi. Thanks for your question.  

Error says that you do not have bitbucket-pipelines.yml config file in your triggered repo.  

Please, check this file preset in repository gemm_fw, and also check that pipelines are enabled in repository gemm_fw.  

Regards, Igor.

comments: author: Brett Steinicke
body: I do indeed have a bitbucket-pipelines.yml config file in my triggered repo and it is properly formatted and I can trigger a build in that repo via the web interface.  
Here is its contents:  
options:  
docker: true  
image: myusername/docker_uhr_utest  
pipelines:  
pull-requests:  
'\*\*': #runs as default for any branch not elsewhere defined  
- step:  
script:  
- set +e  
- git checkout ${BITBUCKET_BRANCH}  
- set -e  
- ./config.sh -b ${BITBUCKET_BRANCH}  
- docker run -v /${BITBUCKET_CLONE_DIR}:${BITBUCKET_CLONE_DIR} --name my_utester -i myusername/docker_uhr_utest /${BITBUCKET_CLONE_DIR}/scripts/run_all_ceed.sh ${BITBUCKET_CLONE_DIR}/.config


author: Igor Stoyanov
body: Try to [trigger the build via API](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-post).   
From your example API has a response 400 with bitbucket-pipelines.yml not found for this url:  
<https://api.bitbucket.org/2.0/repositories/tdwilliamson_ee/gemm_fw/pipelines/>

Try to send request to API without using pipe, in example via CURL in console, and maybe you understand where is the problem.  

I think the problem is with ACCOUNT variable. Maybe you have to provide custom account, instead of default tdwilliamson_ee

Regards, Igor


author: Brett Steinicke
body: Looks like the same failure:  

curl -X POST -is -u uname:app-password -H 'Content-Type: application/json' <https://api.bitbucket.org/2.0/repositories/tdwilliamson_EE/gemm_fw/pipelines/> -d '  
{  
"target": {  
"ref_type": "branch",  
"type": "pipeline_ref_target",  
"ref_name": "master"  
}  
}'  
HTTP/2 400  
server: nginx  
vary: Origin  
x-b3-parentspanid: 18a9750f5304a6a0  
x-cache: Error from cloudfront  
content-type: application/json; charset=utf-8  
x-b3-traceid: 204a27e5e59eb40e  
x-oauth-scopes: pipeline:write, repository  
x-usage-output-ops: 0  
x-dc-location: Micros-3  
strict-transport-security: max-age=31536000; includeSubDomains; preload  
date: Mon, 08 Aug 2022 16:16:50 GMT  
x-usage-user-time: 0.089203  
x-usage-system-time: 0.005242  
x-served-by: c2f9d054706b  
x-b3-spanid: 2ac25fdd8140d1b9  
x-view-name: bitbucket.apps.proxy.views.proxypass  
x-static-version: 25ac997ec994  
x-credential-type: apppassword  
x-render-time: 0.6703824996948242  
x-usage-input-ops: 0  
x-frame-options: SAMEORIGIN  
x-version: 25ac997ec994  
x-request-count: 3662  
content-length: 160

{"error": {"message": "Bad request", "detail": "bitbucket-pipelines.yml not found.", "data": {"key": "result-service.pipeline.yml-not-found", "arguments": {}}}}


author: Brett Steinicke
body: If I add a section to the bitbucket-pipelines.yml file the build is triggered successfully triggered:

```
? branches:
? ? test-branch:
? ? ? - step:
? ? ? ? ? name: Unit Test Pipeline
? ? ? ? ? script:
              - ...
```

Changed the request to be "ref_name": "test-branch"  

So is there a way to trigger a pull-requests entry pipeline build when there is not a created pull-request?

```
pipelines:
  pull-requests:
    '**': #runs as default for any branch not elsewhere defined
    - step:
      script:
```


author: Igor Stoyanov
body: "So is there a way to trigger a pull-requests entry pipeline build when there is not a created pull-request?"  

According to [pipelines config page:](https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/)   
"If you already have branches in your configuration, and you want them all to only run on pull requests, replace the keyword branches with pull-requests."

So if you don't want to create pull requests, just use branches instead of pull-requests  


Tags: atl-gruland

bitbucket-cloud

bitbucket-pipelines

cloud

trigger