3 - Build Workflow

Updated 5 days ago by Michael Cretzman

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

To create a Build Workflow, do the following:

  1. In your Harness Application, click Workflows, and then click Add Workflow. The Workflow dialog appears.
  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.

Jenkins Step

The Jenkins step will run the Jenkins job to build the artifact and then pass an output variable containing the build's environment variables. You will 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 Command. The Add Command dialog appears.

  2. Click Jenkins. The Jenkins dialog appears.

  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:

  1. Click SUBMIT, and the Jenkins step is added to the Workflow.

Shell Script Step

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 dialog appears.
  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.

Artifact Collection Step

The Artifact Collection step will use 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:

  1. 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?