Jenkins and Docker: How can I customize my jenkins pipeline to use docker?

0 votes
How can i customise my jenkins environment to use docker?
Aug 26 in Jenkins by Shayra
287 views

Jenkins Pipeline is the way to go. Have a look at this blog: https://www.edureka.co/blog/jenkins-pipeline-tutorial-continuous-delivery

@Sirajul's explanation is really good. 

1 answer to this question.

+1 vote

Jenkins Pipeline is designed to easily use Docker images as the execution environment for a single Stage or the entire Pipeline. Meaning that a user can define the tools required for their Pipeline, without having to manually configure agents. 

Practically any tool which can be packaged in a Docker container, can be used with ease by making only minor edits to a Jenkinsfile.

Jenkinsfile (Declarative Pipeline)

pipeline {
    agent {
        docker { image 'node:7-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

Jenkinsfile (Scripted Pipeline)

node {
    /* Requires the Docker Pipeline plugin to be installed */
    docker.image('node:7-alpine').inside {
        stage('Test') {
            sh 'node --version'
        }
    }
}

When the Pipeline executes, Jenkins will automatically start the specified container and execute the defined steps within it:

[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
[guided-tour] Running shell script
+ node --version
v7.4.0
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
answered Aug 26 by Sirajul
• 25,420 points

Related Questions In Jenkins

0 votes
1 answer

How can I create global macros and templates in jenkins job builder?

you can append the path to the ...READ MORE

answered Apr 2, 2018 in Jenkins by ajs3033
• 7,280 points
306 views
0 votes
2 answers
0 votes
1 answer

How do I pass value from my Fake # script to the host build server (Jenkins)

You can use the EnvInject plugin to pass environment ...READ MORE

answered Jul 11, 2018 in Jenkins by Kalgi
• 2,620 points
92 views
0 votes
1 answer

I’m facing a login error when I try to run Jenkins on Docker. How do I solve this?

You have to open the /var/log/jenkins/jenkins.log file to ...READ MORE

answered Jul 24, 2018 in Jenkins by Sophie may
• 9,530 points
239 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,520 points
155 views
0 votes
2 answers

How can I point Jenkins to another .jenkins home directory?

Here are the options you have: a) Assuming ...READ MORE

answered Aug 7 in Jenkins by Sirajul
• 25,420 points
223 views