Pipeline Example: Go Build

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

This pipeline demonstrates the definition of a simple pipeline that builds a Go (GoLang) application and Go module. It shows through an example of Pipelines DSL and shows how to use integrations, resources, and steps to construct a simple, automated workflow.

The pipeline performs the following sequence of tasks:

  • Build a Go "Hello World" application using the GoBuild native step

  • Publish the completed Go binary to Artifactory using the GoPublishBinary native step

  • Publish the build info to Artifactory using the PublishBuildInfo native step

See it Live!

Click here to see this quickstart in action.

A successful run of the pipeline in this Quickstart looks like this:

image2021-2-8_21-23-51.png

Before you Begin

Before trying this example, ensure that you have:

  • A GitHub account. This is required for forking the sample repository.

  • A JFrog Platform account, or self-hosted JFrog Pipelines.

  • At least one node pool. This is the set of nodes that all pipeline steps will execute in. For more information, see Managing Pipelines Node Pools. Please note that if you have a Cloud account, a node pool will already be available as part of your subscription.

  • It is recommended that you run go mod tidy command on your local machine to produce the go.sum file and then push it to your Git repo.

Run the Pipeline

Please follow the steps below to build your Go binary:

  1. Fork the repository

    This Pipelines sample is available in the jfrog-pipelines-go-sample repository in the JFrog GitHub account. The configuration is included in YAML files at the root of the repository:

    • pipelines.yml, which contains the declarations for all the resources and steps required to run the pipeline. This configuration is written in template format, so you will not need to change anything in this file.

    • values.yml, which contains custom values that will be populated into the template to create your pipeline

    Fork this repository to your account or organization. This is important since you need admin access to repositories that are used as in your pipelines, in order to enable us to add webhooks to these repositories and listen for change events.

    Note

    The Git repository includes a go.sum file. However, it is recommended that you run go mod tidy command on your local machine to produce a new go.sum file and then push it to your Git repo.

  2. Sign in to Artifactory

    Sign in to JFrog Platform with your Artifactory credentials.

  3. Create the required Go repositories

    You will need to create the following repositories which will be used in your pipeline configuration:

    1. go-local: A local Go repository where your binary will be publishedGo Registry

    2. go-remote: A remote Go repository that proxies https://proxy.golang.org/Go Registry

    3. go-virtual: A virtual Go repository that aggregates local and remote repositories and is used in your pipeline definition to resolve dependencies. Please ensure that you select your local and remote repositories in the Repositories section while creating this virtual repo.Go Registry

  4. Add Integrations

    1. Go to Administration | Pipelines | Integrations to add two integrations:

    2. Write down the names of both GitHub and Artifactory integrations as these are required for the next step . Ensure that the names are unique and easy to remember.

  5. Update pipeline definitions

    Since your pipelines.yml config file is templatized, you can just update values.yml in your forked repository by following instructions below.

    Tag

    Description

    Example

    gitProvider

    Provide the name of the Github integration you added in the previous step (4).

    gitProvider: myGithubIntegration

    repoPath

    Provide the path to your fork of this repository.

    repoPath: myuser/jfrog-pipelines-maven-sample

    artifactory

    Provide the name of the Artifactory integration you added in the previous step (4).

    artifactory: myArtifactoryIntegration

    And that's it. Your configuration is ready to go!

    Note

    All pipeline definitions are global across JFrog Pipelines within a Project. The names of your pipelines and resources need to be unique within the Project in JFrog Pipelines.

  6. Add Pipeline Sources

    A Pipeline Source represents the git repository where our pipelines definition files are stored. A pipeline source connects to the repository through an integration, which we added in step 4.

    1. In your left navigation bar, go to Administration | Pipelines | Pipeline Sources. Click on Add a Pipeline Source and then choose From YAML. Follow instructions to add a Pipeline Source. This automatically adds your configuration to the platform and pipelines are created based on your YAML.

    2. After your pipeline source syncs successfully, navigate to Pipelines | My Pipelines in the left navbar to view the newly added pipeline. In this example, go_build_pipeline_example is the names of your pipeline.

      image2021-2-8_21-46-38.png
    3. Click the name of the pipeline. This renders a real-time, interactive, diagram of the pipeline and the results of its most current run.

  7. Execute the Pipeline

    You can trigger the pipeline by committing a change to your repository, or by manually triggering it through the UI.

    image2021-2-8_21-49-33.png
    image2021-2-8_21-50-33.png
  8. Success!

    You have successfully executed the sample go application pipeline! You can verify the results by viewing the binary and build created by the pipeline.

    Navigate to Application | Artifactory | Artifacts and you will find your published binary under the go-local repository:

    image2021-2-8_21-57-25.png

    Navigate to Application | Artifactory | Builds to view your published build - go_build_pipeline_example.

    image2021-2-8_21-56-39.png

Example of Pipeline Definition

Let us now take a look at the pipeline definition files and what each section means.

The pipelines.yml file contains the templatized definition of your pipeline. This consists of the following:

  • Resources are entities that contain information that is consumed or generated by pipeline steps. In our example, we use the following resources:

    • A GitRepo resource pointing to the source control repository where your application code is present. You can configure this resource to trigger dependent steps on specific events.

    • A BuildInfo resource that is a pointer to the Build on Artifactory. This is automatically created by the PublishBuildInfo step.

  • Steps are executable units that form your pipeline. In our example, the pipeline consists of the following steps:

    • A GoBuild native step that builds your Go project. This step is a pre-packaged step (i.e. native step) that is available to use with simple configuration and without the need for custom scripting. Detailed information on GoBuild is available here.

    • A GoPublishBinary native step that publishes your Go binary to Artifactory. This step also does not need custom scripting. Detailed information on GoPublishBinary is available here

    • A PublishBuildInfo step is a native step that gathers build metadata and pushes it to Artifactory. Artifactory Builds provide a manifest and include metadata about included modules, dependencies and other environment variables. Detailed information on PublishBuildInfo is available here.