Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

bitbucket-clear-cache pipe: doesn't clear cache unless in a separate step

AZZ November 5, 2022

hello,

 as per suggestion here, i added the pipe.

Code:

steps:
- step: &Build
name: Build
services:
- docker
caches:
- docker
script:
- echo $BITBUCKET_USERNAME
- pipe: atlassian/bitbucket-clear-cache:3.1.1
variables:
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BITBUCKET_USER_APP_TOKEN
- branch=$( echo "${BITBUCKET_BRANCH////_}" | tr '[:upper:]' '[:lower:]' )
- export IMAGE=$BITBUCKET_REPO_SLUG_$branch
- echo "export IMAGE=$IMAGE" > image.var
- export DOCKER_FILE="dockerfile"
- docker images
- docker builder build -t $IMAGE -f $DOCKER_FILE .
- docker images
artifacts:
- image.var
- step: &Deploy
name: Deploy Docker image
deployment: Test
services:
- docker
clone:
enabled: false
caches:
- docker
script:
- source image.var
- echo "Image - $IMAGE "
- docker images
- docker login -u $SERVICE_ACCOUNT -p $SERVICE_ACCOUNT_TOKEN
- docker push $IMAGE

on the first run, the "docker images" has no images, and after the "docker builder build" I do see :

docker images

 + docker images

REPOSITORY               TAG      IMAGE ID CREATED SIZE
feature_smsms-44          latest   bb3a0db7c4e6 About a minute ago 82.7MB

which is expected.

on the second run:

Build setup
...
Cache "docker": Downloading
Cache "docker": Downloaded 71.4 MiB in 4 seconds
Cache "docker": Extracting
Cache "docker": Extracted in 1 seconds

...
pipe: atlassian/bitbucket-clear-cache:3.1.1
+ docker container run \
...
bitbucketpipelines/bitbucket-clear-cache:3.1.1
INFO: Executing the pipe...
✔ Retrieved 1 caches
✔ Successfully cleared cache docker
✔ Finished clearing caches
...
docker images
+ docker images
REPOSITORY             TAG       IMAGE ID     CREATED SIZE
feature_smsms-44       latest    bb3a0db7c4e6 About a minute ago 82.7MB
node 10-alpine aa67ba258e18 19 months ago 82.7MB
bitbucketpipelines/bitbucket-clear-cache 3.1.1 7634a1db29b8 23 months ago 128MB

 

Build teardown                  <1s
 

Skipping assembly of docker cache as one is already present

Searching for files matching artifact pattern .bitbucket/pipelines/generated/pipeline/pipes/**

Searching for files matching artifact pattern image.var

Artifact pattern image.var matched 1 files with a total size of 30 B

Compressed files matching artifact pattern image.var to 130 B in 0 seconds

Uploading artifact of 130 B

Successfully uploaded artifact in 0 seconds

 

Is this pipe supposed to run in a separate step only? It kind of makes sense, but the documentation does not mention that.

 

And the follow-up:

 documentation does not describe the variable "debug", though the code displays it. Setting the debug has no visible effect on the pipe output.

 

 

 

 

1 answer

0 votes
Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 10, 2022

@AZZ hi. Thanks for your question.

According to the blog post you should use pipe like this:

pipelines:
  default:
    - step:
        name: delete cache if changes in the build dependencies
        script:
          - pipe: atlassian/bitbucket-clear-cache:3.1.1
            variables:
                 BITBUCKET_USERNAME: $BITBUCKET_USER_NAME
                 BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
                 CACHES: ["node"]
    - step:
        name: build and create/reuse the cache
        caches:
          - node
        script:
          - npm install
          - npm test

Examples in pipe README  describes only simple use cases, so that's it's not covered there. We will extend with advanced example of usage according to your suggestion.

Also we will investigate support of DEBUG variable and notify you.

Regards, Igor

Suggest an answer

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

Atlassian Community Events