diff --git a/12-basic-jenkinsfile.md b/12-basic-jenkinsfile.md index e69de29..3d5a970 100644 --- a/12-basic-jenkinsfile.md +++ b/12-basic-jenkinsfile.md @@ -0,0 +1,62 @@ +# Building Continuous Delivery (CD) Pipelines + +## 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. +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. + 7.1 The job can run on all agents. + 7.2 The job sets the environment variable `GO111MODULES=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 command `go build`. + +
Show Solution +

+ +Create a new job. + +![New Job](./images/12-basic-jenkinsfile/new-job.png) + +Configure the appropriate SCM. + +![Job SCM](./images/12-basic-jenkinsfile/job-scm.png) + +Install the Go plugin. + +![Go Plugin](./images/12-basic-jenkinsfile/go-plugin.png) + +Configure a Go runtime as global tool. + +![Go Global Tool](./images/12-basic-jenkinsfile/go-global-tool.png) + +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. + +![Declarative Pipeline](./images/12-basic-jenkinsfile/declarative-pipeline.png) + +

+
\ No newline at end of file diff --git a/images/12-basic-jenkinsfile/declarative-pipeline.png b/images/12-basic-jenkinsfile/declarative-pipeline.png new file mode 100644 index 0000000..11f19da Binary files /dev/null and b/images/12-basic-jenkinsfile/declarative-pipeline.png differ diff --git a/images/12-basic-jenkinsfile/go-global-tool.png b/images/12-basic-jenkinsfile/go-global-tool.png new file mode 100644 index 0000000..10602f1 Binary files /dev/null and b/images/12-basic-jenkinsfile/go-global-tool.png differ diff --git a/images/12-basic-jenkinsfile/go-plugin.png b/images/12-basic-jenkinsfile/go-plugin.png new file mode 100644 index 0000000..ec62a6a Binary files /dev/null and b/images/12-basic-jenkinsfile/go-plugin.png differ diff --git a/images/12-basic-jenkinsfile/job-scm.png b/images/12-basic-jenkinsfile/job-scm.png new file mode 100644 index 0000000..c93b695 Binary files /dev/null and b/images/12-basic-jenkinsfile/job-scm.png differ diff --git a/images/12-basic-jenkinsfile/new-job.png b/images/12-basic-jenkinsfile/new-job.png new file mode 100644 index 0000000..ecb0b06 Binary files /dev/null and b/images/12-basic-jenkinsfile/new-job.png differ