Go Builds with Artifactory - Declarative Pipeline Syntax

JFrog Integrations Documentation

Content Type
Integrations
ft:sourceType
Paligo

While building your Go projects, Jenkins can resolve dependencies, deploy artifacts and publish build-info to Artifactory.

Note

Please make sure that the go client is included in the build agent's PATH.

To run Go builds with Artifactory from your Pipeline script, you first need to create an Artifactory server instance, as described in the Creating an Artifactory Server Instance section.

The next step is to define an rtGoResolver closure, which defines the dependencies resolution details, and an rtGoDeployer closure, which defines the artifacts deployment details. Here's an example:

rtGoResolver (
    id: 'resolver-unique-id',
    serverId: 'Artifactory-1',
    repo: 'libs-go'
)
       
rtGoDeployer (
    id: 'deployer-unique-id',
    serverId: 'Artifactory-1',
    repo: 'libs-go-local',
    // Attach custom properties to the published artifacts:
    properties: ['key1=value1', 'key2=value2']
)

As you can see in the example above, the resolver and deployer should have a unique ID, so that they can be referenced later in the script, In addition, they include an Artifactory server ID and the name of the repository.

Now we can use the rtGoRun closure, to run the build..Notice that the closure references the resolver we defined above.

rtGoRun (
    path: 'path/to/the/project/root',
    resolverId: 'resolver-unique-id',    
    args: 'build'
    // If the build name and build number are not set here, the current job name and number will be used:
    buildName: 'my-build-name',
    buildNumber: '17',
    // Optional - Only if this build is associated with a project in Artifactory, set the project key as follows.
    project: 'my-project-key'
)

Now that the project is built, you can pack and publish it to Artifactory as a Go package. We use the rtGoPublish closure with a reference to the deployer we defined.

rtGoPublish (
    path: "path/to/the/project/root',
    deployerId: 'deployer-unique-id',
    version: '1.0.0'
)

The last thing you might want to do, is to publish the build-info for this build. See the Publishing Build Info to Artifactorysection for how to do it.

More about build-info: You also also have the option of customising the build-info module names. You do this by adding the module property to the rtGoRun or rtGoPublish closures as follows:

rtGoRun (
    path: 'path/to/the/project/root',
    resolverId: 'resolver-unique-id',    
    args: 'build',
    module: 'my-custom-build-info-module-name'
)

rtGoPublish (
    path: 'path/to/the/project/root',
    deployerId: 'deployer-unique-id',
    version: '1.0.0',
    module: 'my-custom-build-info-module-name'
)