# Creating custom actions in Buddy

- Author: Maciek Palmowski (https://maciekpalmowski.dev/)
- Published: 2022-12-31, updated 2023-01-02
- Topics: cicd, buddy
- URL: https://maciekpalmowski.dev/blog/creating-custom-actions-in-buddy/

> Learn how to create custom sharable actions in Buddy CI/CD, including storage options, using the CLI boilerplate tool, and structuring actions for teams or open source.

While Buddy was always my favorite CI/CD app, it was missing one feature - sharable custom actions. Luckily for us - it has changed lately and in this article, I will show you how to create them.

I always saw the lack of Custom Actions as the biggest downside of Buddy. There was an action **Custom Build**, but it didn't provide us with any UI options, and it was pretty tedious to share and keep updated.

Luckily, Custom Actions change all of this. From now, you can:

## How to store Custom Actions

There are three ways to do so:

Each is useful in some cases. A separate repository for all your actions is excellent when you work in a company and want to have all your actions in one place.

If you are considering an **Open Source approach**, having separate actions in separate repositories seems best.

But, if you want to create related actions with a project, then adding them to that project's repo is the best solution.

For more information, check out the [official Buddy documentation](https://buddy.works/docs/pipelines/custom-actions).

## How to create a Custom Action

Again, you have a choice. You can either create everything manually based on the documentation or use this [small tool](https://www.npmjs.com/package/buddy-custom-action) I made.

If you decide to use **Buddy Custom Action CLI,** you only need to run `npx buddy-custom-action@latest` and answer a few questions. When you are done, you should have a ready-to-use boilerplate.

*[Image: Buddy action catalogue with the custom actions 'No Deploys on Friday' and 'API Parser' above a grid of stacks such as Node.js, PHP, Python, Cypress and Ruby.]*
*Custom actions*

## Example #1 - No deployment on Friday action

Some time ago, I created this simple action that [prevents deploying on Fridays](https://maciekpalmowski.dev/blog/no-deploy-friday-action/). Let's try to convert it into a Custom Action.

First, I used the `npx buddy-custom-action@latest`. I only provided it with a name and a short description, and I said yes to creating an execute commands section.

This is my boilerplate. Of course, right now, it won't do anything. It's time to add the missing command itself:

Is this all? No - we should also add an icon and name it `action.png`

Now we are done. It was simple. Now it's time to create something more complicated.

> **Note:** You can download the code from **[this repository](https://github.com/palmiak/custom-actions-article)**.

## Example #2 - API Parser

This time, we'll create something more complicated. This action will get data from a given API then it will be parsed with `jq` and in the end, we will pass the result to another action.

Again, let's get started with running the  `npx buddy-custom-action@latest`. We'll also need inputs and outputs this time.

Let's start with the inputs. Inputs are the fields that you can populate with some data. In our case, we will need the following:

I will use the Star Wars API and filter out the character's name.

*[Image: Settings form of the custom Buddy action 'API Parser' with a URL to test and a JQ parse command.]*

Now it's time to add the `exectute_commands`:

It works - we will get **Luke Skywalker** as a result. But, while it works, this action is a bit useless. It would be much better to pass the result to other actions. Let's do it, then.

This is when outputs come in handy:

This will result in a tiny change in how your action looks:

*[Image: The 'API Parser' action's setup tab with the URL, the JQ command and a generated variable named result.]*

Now, we have to change the `execute_commends` too:

From this point, we can use the `result` variable in other actions.

The whole action should look like this:

> **Note:** You can download the code from **[this repository](https://github.com/palmiak/custom-actions-article)**.

## What else can you do?

The sky is the limit here. I see **Custom Actions** as one of the most groundbreaking features in Buddy, and it gives everyone the potential to create and share their own actions. We don't have to wait until developers have time to implement something - now, we can do it independently.

I can't wait to see what actions you will create.
