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 the Up/down arrows, and then select an organization.

  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 a component in an organization in one of two ways:

    1. Select the Up/down arrows next to the organization under Home, and then select a component.

    2. Select Components, and then select a component from the list.

  2. Select Workflows on the left pane.

  3. 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, and then select a component from the list.

  2. Select Workflows on the left pane.

  3. Select EDIT YAML on your workflow.

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

  5. 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 ./...
  6. Select COMMIT.

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

  8. Select Commit to current branch.

  9. Select FINISH.

  10. 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, and then select a component from the list.

  2. Select Runs from the left pane.

  3. Select the run (commit message link) to display the details.

  4. 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.