Create the Build Workflow for Build and Deploy Pipelines

Updated 6 days ago by Michael Cretzman

A Build Workflow doesn't require a deployment environment, unlike other Harness Workflows. It simply runs a build process via Jenkins, Bamboo, or Shell Script, and then saves the artifact to an explicit path.

In this document, Jenkins is used as an example, but Harness supports all the common artifact sources and custom sources.

In this topic:

Before You Begin

Step: Create a Build

To create a Build Workflow, do the following:

  1. In your Harness Application, click Workflows, and then click Add Workflow. The Workflow settings appear.
  2. In Name, enter a name for this Build Workflow, such as Build File.
  3. In Workflow Type, select Build. When you are done, the dialog will look something like this.
  4. Click Submit. The Workflow is created.

By default, only the Artifact Collection step is added. Next, we will add the Jenkins step to build the artifact.

Step: Configure Jenkins

The Jenkins step runs the Jenkins job to build the artifact and then pass an output variable containing the build's environment variables. Use the output variable to configure the Artifact Collection step to obtain the newly build artifact (typically, just its metadata).

To learn more about the Jenkins command, see Using the Jenkins Command.

To add the Jenkins step, do the following:

  1. In the Prepare Steps section of the Workflow, click Add Step.
  2. Select Jenkins. The Jenkins settings appear.
  3. In Jenkins Server, select the Jenkins server you added as a Harness Artifact Server in Harness Account Setup. This is the server that contains the Jenkins job to build the artifact.
  4. In Job Name, select the Jenkins job to build the artifact. Next, we will create an output variable to pass build environment variables to the Artifact Collection step.
  5. Click Jenkins Output in the Context.
  6. In Variable Name, enter the name of the output variable. For example, Jenkins.
  7. In Scope, select Workflow. Selecting Workflow ensures that there are no conflicts with any variables that share this name outside of the Workflow, such as another Workflow in the Pipeline.

    When you are done, the dialog will look something like this.
  8. Click Submit. The Jenkins step is added to the Workflow.

Step: Configure Shell Script

To view the environment parameters contained in the output variable, you can add a Shell Script step and echo the parameters.

  1. In the Prepare Steps section of the Workflow, click Add Command, and then click Shell Script. The Shell Script settings appear.
  2. In Script, enter the following script:

    echo "buildDisplayName: " ${Jenkins.buildDisplayName}

    echo "jobStatus: " ${Jenkins.jobStatus}

    echo "buildUrl: " ${Jenkins.buildUrl}

    echo "buildFullDisplayName: " ${Jenkins.buildFullDisplayName}

    echo "buildNumber: " ${Jenkins.buildNumber}

    echo "description: " ${Jenkins.description}
The ${Jenkins.description} parameter requires Descriptor Setter plugin in Jenkins.

When you deploy the Workflow, the Shell Script command will output all the parameters (${Jenkins.description} is not shown):

Next, we will add the Artifact Collection step and use the ${Jenkins.buildNumber} parameter to obtain the latest build number.

To learn more about the Shell Script command, see Using the Shell Script Command.

You can use these artifact variable expressions in a Shell Script to see the built artifact information (at the end of the Workflow).

Step: Configure Artifact Collection

The Artifact Collection step uses the ${Jenkins.buildNumber} parameter to obtain the latest build number, and then pull the build from the artifact repo. Typically, only the build metadata is pulled by Harness. It depends on the Meta-data Only setting in the Service's Artifact Source.

The Artifact Collection step was added automatically when you created the Build Workflow. You simply need to configure it.

To configure the Artifact Collection step, do the following:

  1. In your Build Workflow, click Artifact Collection. The Artifact Collection dialog appears.
  2. In Artifact Source, select the Artifact Source you set up in your Service.
  3. In Build / Tag, enter the Jenkins step output variable ${Jenkins.buildNumber} parameter to provide this step with the build number of the artifact built in the Jenkins step.
    When you are done, the Artifact Collection dialog will look something like this.
  4. Click Submit. The Artifact Collection step is configured.

    You can run the Build Workflow to test its settings before setting up the rest of the Pipeline. In the following example, the Artifact Collection step displays the artifact metadata Harness obtained, including the Build/Tag. 

Next Step


How did we do?