Example Build Status Message Pipeline

JFrog Pipelines Documentation

ft:sourceType
Paligo

The following example pipeline demonstrates sending build status messages to the source control repository that will create a status log entry for each executed step.

pipeline_example.png

The resources for the pipeline declares the GitRepo of the source control repository.

pipelines.resources.yml

resources:
  - name: myGitRepo
    type: GitRepo
    configuration:
      gitProvider: myGitHub
      path: myaccount/myproject

The pipeline consists of two dummy steps, one that will always execute successfully and one that will always fail to execute. The update_commit_status function will send build status messages to the source repository for each step.

pipelines.steps.yml

pipelines:
  - name: git_status_test
    steps:
      ##
      ## Step 1: Execute a simple, always successful test
      ##
      - name: success_test
        type: Bash
        configuration:
          inputResources:
            - name: myGitRepo
        execution:
          onStart:
            - update_commit_status myGitRepo --message "starting..." --context "$step_name"
          onExecute:
            - update_commit_status myGitRepo --message "running..." --context "$step_name"
            - echo "Hello World!"
          onFailure:
            - update_commit_status myGitRepo --message "Failed!" --context "$step_name"
          onSuccess:
            - update_commit_status myGitRepo --message "Succeeded :-)" --context "$step_name"
 
      ##
      ## Step 2: Execute a simple, always failing test
      ##
      - name: failure_test
        type: Bash
        configuration:
          inputResources:
            - name: myGitRepo
              trigger: false
          inputSteps:
            - name: success_test
        execution:
          onStart:
            - update_commit_status myGitRepo --message "starting..." --context "$step_name"
          onExecute:
            - update_commit_status myGitRepo --message "running..." --context "$step_name"
            - cd fail               # No such directory -- guaranteed to fail
          onFailure:
            - update_commit_status myGitRepo --message "Failed!" --context "$step_name"
          onSuccess:
            - update_commit_status myGitRepo --message "Succeeded :-)" --context "$step_name"

When viewed in the source repository's UI (on GitHub), the build status log for the commit shows both a successful and a failed execution of each step:

github_commit_status.png

Tip

Since the context option is always set to the $step_name environment variable in the example, the receiving source control repository will create a build status log entry for each step.

If you wanted to log only a single build status for the entire pipeline, you might set the context option to the $pipeline_name environment variable instead. To log a build status for each run of the pipeline, you might combine it with the $run_number environment variable:

update_commit_status myGitRepo --context "$pipeline_name:$run_number"