Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article explains how to add branch level restriction using using the Bitbucket Command Line Interface (CLI) app app.

Instructions

Use the the runFromBranchList CLI  CLI action to get the list of branches for a repository and addBranchRestriction to add and the addBranchRestriction action to add branch level restriction.

  1. Ensure that the CLI client file is updated with the required information. 
  2. Execute the below following CLI action: 

    Code Block
    themeMidnight
    --action runFromBranchList --project "project1" --repository "repository1" --common "-a addBranchRestriction --project "project1" --repository "repository1" --branch @branch@ --group "group1""

    OutputThe output of the action is similar to:

    Code Block
    themeMidnight
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch admin/COTtxt-1585834077505 --group group1
    Branch restriction 'read-only' added with id 1.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch master --group group1
    Branch restriction 'read-only' added with id 2.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch ABCD5-1-testing-4132 --group group1
    Branch restriction 'read-only' added with id 3.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch develop --group group1
    Branch restriction 'read-only' added with id 4.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch develop1 --group group1
    Branch restriction 'read-only' added with id 5.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch developer --group group1
    Branch restriction 'read-only' added with id 6.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch admin/COTtxt-1585649449127 --group group1
    Branch restriction 'read-only' added with id 7.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch admin/COTtxt-1585647043498 --group group1
    Branch restriction 'read-only' added with id 8.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch admin/COTtxt-1585646764820 --group group1
    Branch restriction 'read-only' added with id 9.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch testbranch --group group1
    Branch restriction 'read-only' added with id 10.
    
    Run: -a addBranchRestriction --project project1 --repository repository1 --branch branch1 --group group1
    Branch restriction 'read-only' added with id 11.
    
    Run completed successfully. 11 actions were successful 
    
    


  3. Verify Verify the newly added restrictions in the Branch permissions page to see the added restrictions.Image Removed

    Image Added
Info

It is

recommended to

recommended to test the commands in a non-production environment or run the action

with 

with the --simulate parameter to verify the behaviour before deploying.