- Make Jenkins master stable and restorable
- Use Jenkins 2 LTS (2.7.x)
- Have a Jenkins testbed/staging environment
- Set up example jobs, test your builds in staging prior to production
- Conservatively upgrade plugins, they can break
- Backup your configuration (
thinBackup
plugin within Jenkins) - Avoid the "Maven" job type (use freestyle job, select Maven as a build step)
- Multiple masters (split across team, function access...)
- More agility & control
- Isolates impact of upgrades/plugin installation
- More masters with fewer jobs tend to be more stable
- Break up or transform your jobs, reuse code
- Multi-job builds allow generic jobs across multiple projects
- Jenkins Pipeline makes larger jobs more understandable and durable
- Parameterized trigger + conditional build steps
- Copy artifact
- Promoted builds
- Transform Jobs to Pipelines (define your jobs in code, check
Jenkinsfile
into repository) - Run steps on different nodes, checkout multiple repositories
- One Pipeline can do far more than one job
- Script Console and Scriptler (access entire system, use Groovy scripts)
- Scriptler examples at https://github.com/jenkinsci/jenkins-scripts
- System Groovy build steps (caution: this gives the build full access to Jenkins)
- Generate jobs from code (REST API & CLI let you POST new jobs and changes to existing jobs)
- Jenkins Job Builder translates YAML into jobs
- Autodiscovery and creation of items in Jenkins with BitBucket Team/Project Folder plugins
- Blue Ocean, user experience built on top of Pipelines (see what stage your build is in)
- Do I need this plugin? They can affect load and run time for jobs
- Periodically uninstall plugins you don't need/use
- Under "Manage Jenkins" view, watch for notices about "old data" and remove as necessary
- Essential plugins: Job Config History, Pipeline Stage View, Timestamper, Rebuild
- Pipelines replaces many older plugins
- Global configuration: Some plugins have global settings in "Configure Jenkins", remember to check this
- Browserstack, SauceLabs
- Via plugins and REST API, trigger builds on pull requests, update JIRA etc... (find more on Jenkins wiki)
- Source Control
- Code Review, build every proposed change, enable automatic merging
- Generate JIRA release notes on every build
- Docker is smoothly integrated into Jenkins Pipeline (additional plugins for building Docker images, running builds in containers, tracing containers between jobs, integrating with container providers like Kubernetes)
- Agents should be easily and readily replaced (if one fails or is busy, add more)
- The easier it is to add agents, the easier it will be to replace them
- Puppet, Chef, Docker
- Try to make agents general purpose
- Avoid customizing an agent for one job
- Interchangeable agents allow for more efficient use of Jenkins resources
- Use cloud resources (AWS)
- https://jenkins.io
- Extend existing plugins or create new ones
- Andy Pemberton
- Install Jenkins Enterprise, create a Jenkins Pipeline, try the basics...
- Install Jenkins Enterprise: https://cloudbees.com/get-started
- What is Jenkins (an automation server, continuous deployment & integration)
- Automate 1. build, 2. test, 3. deployment
java -jar jenkins.war
- Extensible, exposes plugin API
- Can connect additional agents to master, can run builds for iOS, Windows, anything that supports SSH
- CloudBees Jenkins Enterprise (part of CloudBees Jenkins Platform)
- Jenkins Pipeline is new job type (like freestyle job)
- Very durable, will keep running even if Jenkins master is not (can restart master while Pipeline is running)
- Pipeline Stage View provides status at a glance
- Store Jenkinsfile in Git, link it in Pipeline configuration
- Keywords:
stage
= group your steps into component parts (such as build, test, deploy)node
= schedule the steps to run by adding them to Jenkins build queue and creates a workspace specific to this pipelinesh
orbat
= execute shell scripts, just like freestyle jobsgit
= checkout from source controlstash
= store some files for later useunstash
writeFile
readFile
retry(5) {
// some block
}
timeout(time: 30, unit: 'SECONDS') {
// some block
}
input
= get user input (such as "Should we continue deploy?")
stage('deploy')
input message: 'Do you want to deploy?'
node {
echo 'Deployed'
}
parallel
= run tasks in parallelcheckpoint
= allow failed Pipeline to restart from specified checkpoint- Any
Jenkinsfile
should run anywhere
Sample Pipeline code:
stage 'build'
node {
// git '... .git'
// sh 'pwd'
echo 'Build something.'
}
stage 'test'
node {
echo 'Test something.'
}
stage 'deploy'
node {
echo 'Deploy something.'
}
- Binds a tool installation to a variable
- The tool home directory is returned
- Only tools already configured are available
- This may be less useful on AWS/Docker, since this caches resources
def mvnHome = tool 'M3'
sh "${mvnHome}/bin/mvn -B verify"
- CloudBees Docker Pipeline plugin allows running inside a container
- You can even build the container as part of the same Pipeline
docker.image('maven:3.3.3-jdk-8').inside() {
sh 'mvn -B verify'
}
mail body: 'Uh oh.', subject: 'Build failed!', to: 'myles@gumgum.com'
wrap([$class: 'AmazonAwsCliBuildWrapper', credentialsId: 'aws-beanstalk-credentials', defaultRegion: 'us-east-1']) {
sh 'aws elasticbeanstalk create-application-version'
}
jiraComment(issueKey: "EX-111", body: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) built. Please go to ${env.BUILD_URL}.")
- Use pull requests & specific branches
- Viktor Farcic
sudo docker-compose -f docker-compose-test.yml up -d staging-dep
terraform destroy
to destroy AWS instance (using Terraform)- Swarm cluster
docker network
docker service
docker service scale go-demo=5
docker service update
docker service create --name jenkins