What is Jenkins?
Jenkins is an open source CI&CD software for automating a variety of tasks, including building, testing, and deploying software.
This post will cover the automatic build part.
Build Jenkins +GITHUB Continuous integration environment from scratch.
The content of the presentation includes:
-
New assembly line
-
Jenkins configuration
-
Gitlab configuration
Get right to the point
New assembly line
Dashboard -> Create a task
✅ Suggestion: The task name must be the same as the warehouse name to facilitate task search.
After a task is created, the configuration page of the task is displayed.
Jenkins configuration
The configuration here, to do a little subdivision.
Common configuration
The system configuration
Dashboard -> System Administration -> System Configuration -> Gitlab
- Connection name indicates the name of the link. Here I fill in Gitlab, which will be used later
- The Gitlab host URL represents your Gitlab domain name link
- Proof of Credentials
- To obtain the voucher, click “Add”
- Specific generation steps personal_access_tokens
Global Tool Configuration
Dashboard -> System Management -> Global Tool Configuration – NodeJS
- The alias is given here
nodejs
We’ll use it later when we write Jenkinsfile - The installed version is the current stable version. At the time of publication,
NodeJS
The stable version of theNodeJS 14.17.5
Task allocation
If you perform normal operations, the operation page is automatically displayed after a task is created. Of course, you can also enter by:
Dashboard -> PipelineTask -> Configuration
Just keep an eye out for the following:
- The General plate
- What does the description say the task is, optional
- GitLab Connection selects the options we set up in System Configuration
- Building trigger blocks
- As long as the check
Build when a change is pushed to GitLab. GitLab webhook URL: http://localhost:8080/project/PipelineTask
Can be
- As long as the check
🀄️ there are two things that need to be used later (the screenshot above is not complete, for myself) :
- GitLab webhook URL
- Secret Token (Click “Advanced” -> Generate button)
- Pipeline module
- Define the drop down box to select Pipeline Script from SCM as we go through the project
Jenkinsfile
constructed - SCM choice Git
- Repository URL Specifies the Repository address of the project, for example
https://gitlab.mydomain.com/apps/pipeline_task.git
- Credentials are Credentials, your GitLab account password
- Define the drop down box to select Pipeline Script from SCM as we go through the project
Gitlab configuration
An association is made on Gitlab, which is associated with Jenkins. When the warehouse pushes, Jenkins automatically builds the project.
🀄️ PS: Of course, push is only one of the cases, and you can also tag things like that
Go to your repository -> Settings -> Integrations
- URL corresponds to the GitLab Webhook URL set on Jenkins trigger above
- Secret Token corresponds to the Secret Token generated on Jenkins trigger above
After adding Webhook, you can test to see if it works.
Hook executed successfully: HTTP 200 is displayed if the test passes.
Before triggering the build, we write a simple script Jenkinsfile in the corresponding repository root:
pipeline {
agent any
tools {
nodejs "nodejs"
}
stages {
stage('Dependency') {
steps {
sh 'npm install'
}
}
stage('Build') {
steps {
sh 'npm run clean'
sh 'npm run build'
}
}
}
}
Copy the code
Every time the project is pushed, it is automatically built, and the build steps follow the Jenkinsfile Settings.
【 the 】