1.8 KiB
1.8 KiB
Building Continuous Delivery (CD) Pipelines
Writing a basic Jenkinsfile
- Create a new GitHub repository named
go-on-jenkins. - Create a new
Jenkinsfilein the root directory of the repository as well as a simplemain.gofile. The main function just prints "Hello World!". Initialize the project via Go Modules. - Commit the files and push them to the remote repository.
- Set up a new pipeline job for this repository in Jenkins.
- Install the Jenkins Go plugin.
- Configure the latest Go runtime as global tool.
- Enhance the
Jenkinsfilebased on the following requirements. The Jenkinsfile should use the declarative syntax. 7.1 The job can run on all agents. 7.2 The job sets the environment variableGO111MODULES=on. 7.3 The job uses the Go runtime from the global tool definition. 7.4 The job specifies one build stage named "Build". The build stage executes the shell commandgo build.
Show Solution
Create a new job.
Configure the appropriate SCM.
Install the Go plugin.
Configure a Go runtime as global tool.
The final Jenkinsfile looks similar to the solution below.
pipeline {
agent any
tools {
go 'go-1.12'
}
environment {
GO111MODULE = 'on'
}
stages {
stage('Build') {
steps {
sh 'go build'
}
}
}
}
A build of the job installs the Go runtime and executes the build step.




