CICD Process — Cloning your repo with OAuth in BitBucket Cloud

Gastón Gamietea
2 min readSep 24, 2021

--

While we code our project we usually are worried only in cloning the repository with our credentials (username/password) or even using SSH Keys, which is my preferred option, and that’s fine for your local but what happen when you need to clone your code from external location?

During the CICD process we could do some temporary changes in the code but we don’t usually need to push them so in reality we only need read-only access. To do that BitBucket Cloud provides OAuth consumers.

Changes in your Bitbucket workspace

  1. Login to BitBucket Cloud
  2. Go to the workspace we want to connect our Jenkins to
  3. Click on settings
  4. Click on OAuth consumers
  5. Click on Add consumer
  6. Fill out Name and Callback URL (in my case I just add the workspace home url but it doesn’t really matter on this example)
  7. We ONLY select Repositories — READ
  8. Click on Save

After these steps you should have a client-id and client-secret.

consumer’s name, key and secret

Changes in your Jenkins Pipeline

Once we have the OAuth consumer in place we can now enable our jenkins pipeline to use it in a one liner.

This will clone your code into Code directory…

Happy coding…

--

--

Gastón Gamietea

father, husband, golfer, engineering manager, application & cloud architect, change agent