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, 2019 in Jenkins by Shayra
1,733 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, 2019 by Sirajul
• 59,230 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,300 points
1,885 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,680 points
1,391 views
+2 votes
1 answer
+2 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
• 58,020 points
2,739 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, 2019 in Jenkins by Sirajul
• 59,230 points
5,027 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP