Initial commit
This commit is contained in:
17
exercises/12-basic-jenkinsfile/instructions.md
Normal file
17
exercises/12-basic-jenkinsfile/instructions.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Exercise 12
|
||||
|
||||
In this exercise, you'll create a declarative pipeline for a Go-based project. The `Jenkinsfile` will use some of the basic features of the pipeline DSL.
|
||||
|
||||
## Writing a Basic Jenkinsfile
|
||||
|
||||
1. Create a new GitHub repository named `go-on-jenkins`.
|
||||
2. Create a new `Jenkinsfile` in the root directory of the repository as well as a simple `main.go` file. The main function just prints "Hello World!". Initialize the project via Go Modules.
|
||||
3. Commit the files and push them to the remote repository.
|
||||
4. Set up a new pipeline job for this repository in Jenkins.
|
||||
5. Install the [Jenkins Go plugin](https://plugins.jenkins.io/golang).
|
||||
6. Configure the latest Go runtime as global tool.
|
||||
7. Enhance the `Jenkinsfile` based on the following requirements. The Jenkinsfile should use the declarative syntax.
|
||||
* The job can run on all agents.
|
||||
* The job sets the environment variable `GO111MODULES=on`.
|
||||
* The job uses the Go runtime from the global tool definition.
|
||||
* The job specifies one build stage named "Build". The build stage executes the shell command `go build`.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 906 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 706 KiB |
BIN
exercises/12-basic-jenkinsfile/solution/images/go-plugin.png
Normal file
BIN
exercises/12-basic-jenkinsfile/solution/images/go-plugin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 864 KiB |
BIN
exercises/12-basic-jenkinsfile/solution/images/job-scm.png
Normal file
BIN
exercises/12-basic-jenkinsfile/solution/images/job-scm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 760 KiB |
BIN
exercises/12-basic-jenkinsfile/solution/images/new-job.png
Normal file
BIN
exercises/12-basic-jenkinsfile/solution/images/new-job.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 902 KiB |
54
exercises/12-basic-jenkinsfile/solution/solution.md
Normal file
54
exercises/12-basic-jenkinsfile/solution/solution.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Solution
|
||||
|
||||
Create a new job.
|
||||
|
||||

|
||||
|
||||
Configure the appropriate SCM.
|
||||
|
||||

|
||||
|
||||
Install the Go plugin.
|
||||
|
||||

|
||||
|
||||
Configure a Go runtime as global tool.
|
||||
|
||||

|
||||
|
||||
The `main.go` file could similar to the one below.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("hello world")
|
||||
}
|
||||
```
|
||||
|
||||
The final `Jenkinsfile` looks similar to the solution below.
|
||||
|
||||
```groovy
|
||||
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.
|
||||
|
||||

|
||||
Reference in New Issue
Block a user