I'm trying to convert my existing Jenkins Freestyle Golang Job into a Jenkinsfile that I can check-in along with my project so I can use it in a Pipeline Job instead.
Said job is simply running all Go tests and Building the project if all tests pass. Deployment is not yet a concern of this job.
My working setup is as follows:
Go Plugin Installations:
Name: Go
Install Automatically: Checked
Install from golang.org: Go 1.11.2
NOTE: I gave it the name Go
so the Go installation folder portion Go/src
can be consistent in the directories below.
Credentials (Global):
Username with password: (My email address and password)
Job Configuration:
Use custom workspace: Checked
Directory: /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
Source Code Management:
Git
Repository URL: MY_PRIVATE_BITBUCKET_URL.git
Credentials: (My email address and password)
Branches to build: */master
Build Environment:
Set up Go programming language tools: Checked
Go version: Go
Build
Execute Shell
# Remove cached test results.
go clean -cache
# Run all Go tests.
cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
go test ./... -v
Execute Shell
# Build the project.
cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
go build
I tried using the Convert To Pipeline
plugin, but it was not able to completely convert the job:
// Powered by Infostretch
timestamps {
node () {
stage ('MY_PROJECT_NAME - Checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'MY_CREDENTIALS_ID', url: 'MY_PRIVATE_BITBUCKET_URL.git']]])
}
stage ('MY_PROJECT_NAME - Build') {
// Unable to convert a build step referring to "org.jenkinsci.plugins.golang.GolangBuildWrapper". Please verify and convert manually if required.
// Shell build step
sh """
cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
go clean -cache
go test ./... -v
"""
// Shell build step
sh """
cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
go build
"""
}
}
}
How do I convert this simple Job into a Jenkinsfile? I am also willing to integrate Docker into said file if necessary.