Quickstart: Create a build workflow

3 minute read

The core of the CloudBees platform is the workflow, a DevSecOps automation. In this quickstart, create a workflow to build a sample Go application, then run the workflow.

Prerequisites

Complete the Quickstart: Connect to source code management that connects a sample Go app repository to the platform.

Create a component

Create a component that contains all the resources required to build a sample Go app in the CloudBees platform.

To create a component:

  1. Select Components from the left pane.

  2. Select CREATE COMPONENT.

  3. Select your sample Go app repository from the options. If desired, enter all or part of its name into Search, and then select it.

  4. Select NEXT.

  5. Enter a Component name.

  6. (Optional) Enter a Description.

  7. Select CREATE.

Your component is created, and you are ready to create a workflow to automate building your Go app.

Create a workflow

Create a CloudBees workflow with the composer code editor.

The workflow displayed in the visual tool automatically updates with every change you make to the script in the code editor.

To create a workflow:

  1. Select Components from the left pane, select your component, and then select Workflows.

  2. Select CREATE WORKFLOW.

An example workflow that outputs "hello world" is displayed in the composer.

Hello world output workflow
Figure 1. Default workflow which outputs "hello world".

Update the workflow

In the code editor, add a new CI job, then commit these changes to your repository.

This job performs the following steps:

To add the new CI job using the code editor:

  1. Select Components from the left pane, and then select your component name from the list.

  2. Select EDIT YAML on your workflow.

  3. Delete the build job that outputs "hello world", on lines 11 - 17.

  4. Enter the following, starting on line 11:

    ci-job: steps: - uses: docker://alpine/git:latest run: | git config --global --add safe.directory /cloudbees/workspace - name: checkout uses: cloudbees-io/checkout@v1 - name: Build Go app uses: docker://golang:1.20 run: | go build -v ./... - name: Run tests uses: docker://golang:1.20 run: | go test -v ./...

    Check to confirm that your YAML script is similar to the following:

    Display the complete YAML file for building the sample Go app.
    apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: My automation on: push: branches: - '**' jobs: ci-job: steps: - uses: docker://alpine/git:latest run: | git config --global --add safe.directory /cloudbees/workspace - name: checkout uses: cloudbees-io/checkout@v1 - name: Build Go app uses: docker://golang:1.20 run: | go build -v ./... - name: Run tests uses: docker://golang:1.20 run: | go test -v ./...
  5. Select COMMIT.

    To save changes to your workflow, you must make a commit.
  6. Enter a Commit message.

  7. Select Commit to current branch.

  8. Select FINISH.

  9. Check your repository for the commit.

    All CloudBees platform workflows are saved in .cloudbees/workflows in your connected repository.
    First commit
    Figure 2. Commit in connected GitHub repository.

You have created a workflow to build a sample Go app, using the code editor in the composer, and triggered a workflow run.

Check your workflow run

  1. Select Components from the left pane, select your component, and then select Runs.

  2. Select Display run to the right of your run.

  3. Select ci-job to display each job step, and then select EXPAND ALL on the upper right to display all step details.

You have run a workflow triggered by a commit to the main branch of your repository, and checked your workflow run details. You are now ready to scan your repository for security flaws.