Go Builds with Artifactory - Scripted Pipeline Syntax

JFrog Integrations Documentation

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.

Here's an example:

def server = Artifactory.server 'my-server-id'

The next step is to create an Artifactory Go Build instance:

def rtGo = Artifactory.newGoBuild()

Now let's define where the Go build should download its dependencies from. We set the Artifactory server instance we created earlier and the repository name on the resolver:

rtGo.resolver server: server, repo: 'go-virtual'

Now let's build the project. Here's how we do it:

def buildInfo = rtGo.run path: 'path/to/the/project/root', args: 'build'

Note

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

The above method returns a buildInfo instance. If we already have a buildInfo instance we'd like to reuse, we can alternatively send the buildInfo as an argument as shown below. Read the Publishing Build-Info to Artifactory section for more details.

rtGo.run path: 'path/to/the/project/root', args: 'build', buildInfo: my-build-info

You also have the option of customising the build-info module name associated with this build. You do this as follows:

def buildinfo = rtGo.run path: 'path/to/the/project/root', args: 'build', module: 'my-build-info-module-name'

Now that the project is built, you can pack and publish it to Artifactory as a Go package. We start by defining the deployer:

rtGo.deployer server: server, repo: 'go-local'

The following method will do two things: package the code and publish it to Artifactory:

def buildInfo = rtGo.publish path: 'golang-example/hello', version: '1.0.0'

If you already have a buildInfo instance configured, you can pass it as an argument as follows:

rtGo.publish buildInfo: buildInfo, path: 'path/to/the/project/root', version: '1.0.0'

You also have the option of customising the build-info module name associated with this build. You do this as follows:

def buildinfo = rtGo.publish path: 'path/to/the/project/root', version: '1.0.0', module: 'my-build-info-module-name'

You can now publish the build-info to Artifactory as described in the Publishing Build-Info to Artifactory section