- (optional) scm //where jenkin find source code to build, git etc
- (optional) trigger to build
- build script to perform the build //ant, maven, shell script, batch file etc
- (optional) steps to notify //email, im, issue tracker etc
2. install jenkins on windows
- download jenkins windows installer
- run installer will install jenkins as a windows wervice, and it runs on local SYSTEM account. so it will use 'system environment variable' instead of 'user environment account variable', which will cause trouble (JAVA_HOME etc missing)
- also it will not allow interaction with desktop (selenium browser will run in the background)
- so instead, after run installer, stop jenkins windows service, and run jenkins as 'java -jar jenkins.war'
3. jenkins configuration
- jenkins configuration will read environment variables from windows account
- jenkins allow user to change environment variables
4. build non source control code
- build empty project (will fail), but jenkins will create folder jenkins/workspace/PROJECTNAME/
- copy local project files to the above folder
- build again
5. jenkins email notification
- if using gmail, need to change 'Sign-in & Security' -> 'Signing into Google' -> 'Allow less secure apps: ON'
6. jenkinsfile (declarative and scripted syntax)
pipeline { //declarative
agent any
stages {
stage('Build') {
steps {
//
}
}
stage('Test') {
steps {
//
}
}
}
}
stage('Build') {
//
}
stage('Test') {
//
}
stage('Deploy') {
//
}
}
7. jenkinsfile
- sh """ ... """ //multiline, sh is a 'step' provide by plugin
- def //groovy, define var or func
- readProperties //read file in java property file format
8. parameterise pipeline
- use <JENKINS URL>/pipeline-syntax //snippet generator
- select 'properties' step to generate code
9. jenkins github integration webhook to jenkins
- trigger build whenever commit pushed
- use 'ngrok' if jenkins is localhost
- on github side, config github-webhook
- on jenkins side, github-webhook trigger build when commit happens
10. restart jenkins
- (jenkins_url)/safeRestart
- (jenkins_url)/restart
11. port diagnose
- kill -9 $(lsof -ti tcp:4444)
- netstat -vanp tcp | grep 3000
- ps -p 1337 -o comm=
- fuser -k 5000/tcp || true - kill process in jenkins, without true jenkins will fail
12. withCredentials/usernamePassword
- it's a bind credentials to variable feature
- update ssh key/certificate, and it's converted to env variable
- parameterizedCron(env.BRANCH_NAME == 'master' ? "0 8 * * * %TARGET_ENV=staging;TEST_GROUP=All;TEST_COVERAGE=Regression" : '')
references
1. my software builds on my computer but not on jenkins
3. jenkins pipeline
4. using a jenkinsfile
5. difference between """ and '''
6. jenkins guided tour
7. scripted jenkins
8. add webhook to jenkins pipeline
8. jenkins env variable guide
9. parametrized jenkins pipelines
10. parameter in scripted jenkinsfile
11. add github webhook to jenkins pipeline
12. integration github repo to jenkins
13. how to trigger Multibranch Pipeline build with github webhook
14. kill all processes on specific port via Jenkins
15. configure email in jenkins
16. sending notifications in pipeline
4. using a jenkinsfile
5. difference between """ and '''
6. jenkins guided tour
7. scripted jenkins
8. add webhook to jenkins pipeline
8. jenkins env variable guide
9. parametrized jenkins pipelines
10. parameter in scripted jenkinsfile
11. add github webhook to jenkins pipeline
12. integration github repo to jenkins
13. how to trigger Multibranch Pipeline build with github webhook
14. kill all processes on specific port via Jenkins
15. configure email in jenkins
16. sending notifications in pipeline