Reuse artifacts from one pipeline in another
Asked by Andrei Bereczki:

Hi, I'm having trouble reusing artifacts.

Basically, my bitbuckets-pipelines looks similar to this:

```
pipelines:
? custom:
? ? build:
? ? ? - step:
? ? ? ? ??name: Build #this is the step which builds the artifact
          ... blabla
? ? ? ? ??artifacts:
? ? ? ? ? ? - dist/**
    deploy:
      - step:
          name: Deploy
          deployment: production
          script:
            - ls -al dist #this is where the artifact should get used
```

Now, obviously, that ls command is just to test things out, but it errors out saying dist is not found. Also if i ls -al i just get my regular repo structure, with no dist in sight.

Is there a way to achieve this in separate pipelines, or would i have to make the deploy part of the first pipeline to effectively use artifacts?


Answers:
author: Aron Gombas _Midori_
body: If I correctly understand, here you are defining two pipelines ("build" and "deploy") with one step in each. And sharing artifacts through the file system is possible only between steps in the same pipeline.

(You can test if moving the two steps to the same pipeline works?)

It is still possible to share an artifact between two pipelines. You could for example create a Bitbucket download from the "build" step's result, and access that download from "deploy". You can periodically clean up downloads that are older than N days. (We do something similar in our rather large integration test suite.)

comments: author: Andrei Bereczki
body: Thank you [@Aron Gombas _Midori_](/t5/user/viewprofilepage/user-id/502447)

will try this. Could you maybe share a snippet from your yml, just so i don't waste another half a day figuring out all the required parameters?


author: Aron Gombas _Midori_
body: We post the file to the standard Bitbucket Cloud REST API with all variables and secrets managed in Bitbucket repo variables.

It looks like this in our yml:

```
- curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"$BITBUCKET_CLONE_DIR/${BITBUCKET_BUILD_NUMBER}-results.zip"
```


author: Andrei Bereczki
body: Ok, cool. And how does the download part work?  
Btw, is BITBUCKET_REPO_OWNER a global variable? I couldn't find it on:: <https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/>


author: Aron Gombas _Midori_
body: Download: we don't use that, we only need to download things manually time to time. But I would guess it is just a GET request to the same end-point.

BITBUCKET_REPO_OWNER: I can't recall, but now I checked and it is not listed among our variables, so it should be something populated by default. Why don't you "echo" it and see if that works?


author: Erez Maadani
body: Hi [@Andrei Bereczki](/t5/user/viewprofilepage/user-id/3300229)

In addition to [@Aron Gombas _Midori_](/t5/user/viewprofilepage/user-id/502447) answer, you can also upload your artifacts to standard repos, for example, docker hub for docker, and then you can use standard commands to pull/install your artifacts: "docker pull", "npm install", "pip install", etc'.

comments: author: Andrei Bereczki
body: Hi [@Erez Maadani](/t5/user/viewprofilepage/user-id/5018344)

thank you for the addition. I think i will go with the Bitbucket Downloads solution, although at this point all options are still on the table.

Cheers!


Tags: bitbucket-cloud

bitbucket-pipelines

cloud