Pipelines: Image name as an artifact
Asked by AZZ:

hello,

is there a way to pass docker's image between the steps of a pipeline?

something to this extent:

```
steps:
    - step: &Build
        name: Build an image
        services:
          - docker
        script:
          - export IMAGE=$BITBUCKET_REPO_SLUG_BLAH
          - export DOCKER_FILE="dockerfile"
          - docker builder build -t $IMAGE -f $DOCKER_FILE  .
        artifacts:
          - $IMAGE
    - step: &Deploy
        name: Deploy Docker image
        deployment: Test
        services:
          - docker
        clone:
          enabled: false
        script:
          - docker login -u $SERVICE_ACCOUNT -p $SERVICE_ACCOUNT_TOKEN
          - docker push $IMAGE
pipelines:
  custom:
    Build:
      - step: *Build_And_Scan
      - step: *Deploy
```

```
 
```


Answers:
author: Mark C
body: Hi [@AZZ](/t5/user/viewprofilepage/user-id/5060131),

Thank you for reaching out to the community.

To save the built Docker image and access it in the next step, you can use [Caching](https://support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/).

```
caches:  - docker
```

Using Docker cache, we [create the cache](https://confluence.atlassian.com/bitbucket/run-docker-commands-in-bitbucket-pipelines-879254331.html#RunDockercommandsinBitbucketPipelines-ci_caching) from the layers generated by your build.  
This way, you can access the Docker image in any step within 1 week.

:warning: However, please kindly note that we don't automatically refresh Caches. We do have an existing feature request for it that can be located through this link. - <https://jira.atlassian.com/browse/BCLOUD-16314>  
You can upvote and watch it for now so that you'll be notified of any updates from our team when the feature becomes available on Bitbucket Cloud.

As a workaround, if you'd like to refresh the Docker cache, you will need to clear it first using the Pipes script ([atlassian/bitbucket-clear-cache](https://bitbucket.org/atlassian/bitbucket-clear-cache/src/master/)).  
Here's a blog post on how to use the Pipes script. - [Automatically refresh caches when build dependencies are updated](https://bitbucket.org/blog/automatically-refresh-caches-when-build-dependencies-are-updated)

Hope it helps and do let me know if you have further questions.

Regards,  
Mark C

comments: author: AZZ
body: [@Mark C](/t5/user/viewprofilepage/user-id/1210823),

thank you for the reply.

Does it mean that i do not have to use "artifacts" to pass docker image?


author: AZZ
body: [@Mark C](/t5/user/viewprofilepage/user-id/1210823)

and the additional question:

is there a way to reuse var IMAGE without redefining it in the "deploy" step?

I look at the "stage", but, it seems, i can only define static values for variables there. e.g. I can't have an expression of shell call in there.


author: Mark C
body: Hi [@AZZ](/t5/user/viewprofilepage/user-id/5060131)  

You don't need to use **artifacts** as Caches is available for any steps for 1 week.  
You can also use a [repository variable](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/#Repository-variables) for your Docker image name and that will be available on your steps.  

Regards,  
Mark C


Tags: bitbucket-cloud

cloud