Bitbucket Dependency Bot Using Renovate 🤖
Tags: bitbucket, ci, javascript, webdev
Published: 2023-10-03 09:14:00

## What is [Renovate](https://docs.renovatebot.com/)?

It is a tool that helps developers keep their software projects up to date. It automatically updates dependencies, such as libraries and packages, for security vulnerabilities and outdated versions.

## How do I set up Renovate on Bitbucket Cloud?



####**Step 1** - Create an [access token](https://support.atlassian.com/bitbucket-cloud/docs/create-a-repository-access-token/) on your Bitbucket repo.
This will ensure Renovate has permission to create PRs on your behalf.


![Bitbucket Access Token Screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rt9aarfkkfaxp7opme5.png)


####**Step 2** - Create a pipeline variable using the Access Token as your value.


![Bitbucket pipeline variable screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cf633fz9p6tugg2wkhiw.png)


Creating a pipeline variable will make sure the pipeline that we will create to run Renovate will have access to the Access Token we created.

####**Step 3** - Create a JS file named `renovate.js` with the following code:

`./renovate.js`

```
module.exports = {
  /**
   * Tells which platform Renovate is on.
   * See full platform support here
   * https://docs.renovatebot.com/modules/platform/
   */ 
  platform: 'bitbucket',
  /**
   * This is the Bitbucket variable we create on Step 2
   */
  token: process.env.RENOVATE_TOKEN,
  /**
   * https://docs.renovatebot.com/self-hosted-configuration/#basedir
   */
  baseDir: `${process.env.BITBUCKET_CLONE_DIR}/renovate`,
  /**
   * https://docs.renovatebot.com/self-hosted-configuration/#autodiscover
   */
  autodiscover: true,
};
```

####**Step 4** - Create a JS file named `renovate.json` with the following code:

`./renovate.json`

```
{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "enabledManagers": ["npm"],
  "prHourlyLimit": 4,
  "patch": { "enabled": true },
  "minor": { "enabled": true },
  "major": { "enabled": true },
  "npmrc": "save-exact=true",
  "labels": ["dependencies"]
}
```

This is a basic example of a configuration file that tells Renovate your preferences.
You can see the full list of configurations here:

https://docs.renovatebot.com/self-hosted-configuration

####**Step 5** - Create a custom bitbucket-pipelines.yml step that will run Renovate on a schedule.

`./bitbucket-pipelines.yml`

```
image: node:18.15-slim

pipelines:
  custom:
    'renovate':
      - step:
          name: Check for package updates
          image: renovate/renovate:36.91-slim
          caches:
            - node
            - docker
          services:
            - docker
          script:
            - export LOG_LEVEL=debug RENOVATE_CONFIG_FILE="$BITBUCKET_CLONE_DIR/renovate.js"
            - renovate

```

**2 things to note:**

 - Even if you are not using `bitbucket-pipelines.yml` this step should be similar.
 - I am using the Renovate image version renovate/renovate:36.91-slim which might not be the latest for you.
you can check the latest versions of Renovate here
https://hub.docker.com/r/renovate/renovate/tags


####**Step 6** - [Getting the changelog in each Renovate PR bot to appear](https://github.com/settings/tokens).


In order to get a changelog for each PR we need to add a variable to our pipeline variables on Bitbucket with the key `GITHUB_COM_TOKEN` and the value should be generated from GitHub.

This is a weird one 😅

![Github access token screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dn8ak1fr6gj5tp2fffgn.png)

**How to generate the token on Github?**

- Go to https://github.com/settings/tokens
- Generate a classic token

####**Final Step** 

🎉🎉 Make sure all the code is pushed on your main Git branch (for some reason it doesn't work if renovate is not on the main branch 🤷)

#### Final Note

I hope this guide will save you some time to set it up 💪