Skip to main content

Command Palette

Search for a command to run...

Day27 of 90daysofdevopschallenge

Jenkins declarative pipeline using docker.

Published
1 min readView as Markdown
Day27 of 90daysofdevopschallenge
K

Aspiring Devops engineer

Task-01

  1. Create a docker-integrated Jenkins declarative pipeline

  2. Use the above-given syntax using sh inside the stage block.

    Steps to make Jenkins declarative pipeline.

    1. Open Jenkins Homepage and select “New Item”.

    2. Enter the name of the item and select “Pipeline”.

    3. Write a groovy script to create a docker-integrated Jenkins declarative pipeline that deploys a nptes-app docker container.

  1. After saving the changes, let's build the pipeline.

  2. We can view the outcome of the stages on the Status page.

You will face errors in case of running a job twice, as the docker container will be already created.

Task-02

Let's modify the groovy syntax such that it uses the docker agent and reuses the docker container.

  1. Create a docker-integrated Jenkins declarative pipeline using the docker groovy syntax inside the stage block.

    We can solve the error with the help of docker-compose, by modifying the script using the docker-compose down and up commands.

      stage("code Deploy"){
                  steps {
                      sh 'docker-compose down'
                      sh 'docker-compose up'
                  }
              }
    

    Hence docker-compose will down the container running on port using dockerfile and docker-compose up will run the container. This is how we can troubleshoot the errors.

More from this blog

Untitled Publication

38 posts