Bitbucket Cloud: Managing File Permissions in Bitbucket Cloud Pipelines

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

This article provides solutions for resolving issues related to file permission changes in Bitbucket Cloud pipelines.

Environment

Bitbucket Cloud.

Diagnosis

Upon investigation, it was identified that the file permission issue arises because Bitbucket Pipelines sets the umask to 0022, causing cloned files to have 666 permissions. This results in all files retaining these permissions in the subsequent Docker image.

Cause

Bitbucket Pipeline sets the umask to 0022 for all cloned files, resulting in all cloned files having 666 permissions. Consequently, these files will retain the 666 permissions in the image created within the pipeline.

Solution

To resolve this issue, change the file permissions to the desired settings in the pipeline after the files are cloned and before the image is created

Example: 

If you want to set the permissions to 644, you can run the following command in your configuration file:

chmod 644 test.py


bitbucket-pipelines.yml example:

bitbucket-pipelines.yml
image: atlassian/default-image:4

pipelines:
  branches:
    '*':
      - step:
          name: Build and Set Permissions
          caches:
            - docker
          services:
            - docker
          script:
            - ls -lrt
            - chmod 644 test.py
            - ls -lrt
            - DOCKER_BUILDKIT=1 docker image build --no-cache --progress=plain .

In this configuration:

  • The pipeline runs for all branches ('*').
  • The Build and Set Permissions step includes a script that lists the files with detailed permissions (ls -lrt), changes the permissions of test.py to 644 (chmod 644 test.py), lists the files again to verify the change, and then builds the Docker image.

By incorporating these steps, you can ensure that your files have the correct permissions before the Docker image is created.

If the above instructions do not assist in resolving the issue, please raise a support ticket or raise a community support ticket for further assistance with this.

Last modified on Jun 18, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.