Manage File Permissions in Bitbucket Cloud Pipelines

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.

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:

1 chmod 644 test.py

bitbucket-pipelines.yml example:

bitbucket-pipelines.yml

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 raiseasupport ticketor raise acommunity support ticketfor further assistance with this.

Updated on March 13, 2025

Still need help?

The Atlassian Community is here for you.