Today I will show you how to configure Jenkins to use the images we prepared in the previous post.
You need to launch Jenkins executing @docker-compose up -d@ in the directory where the docker-compose.yaml was created and then go to http://localhost:8080 where Jenkins is going to be running.
First of all, you need to install the Docker Plugin. There are multiple guides on how to do this so I will not cover this today.
Then you need to set up a Docker Cloud. Follow these instructions:
unix:///var/run/docker.sockgrcanosa/jenkins-ssh-slave-did:latest./var/run/docker.sock:/var/run/docker.sock:ro to container settings.docker exec -it devops_jenkins bash.mkdir -p /var/jenkins_home/.ssh/ssh-keygen. Remember to select /var/jenkins_home/.ssh/id_rsa as destination file.cat /var/jenkins_home/.ssh/id_rsa.pub.Now everything is set up to launch a Jenkins pipeline in a docker container. An example of a Jenkinsfile to be used with this template is:
node('docker'){  //Same label as in the docker agent configuration.
  stage('greeting'){
     //prepare our slave container
     echo "grcanosa rulez!" 
     echo "new stage!"
  }
  stage('getting code'){
    git 'https://github.com/grcanosa/grcanosa_ci_test.git'
    GIT_COMMIT_HASH = sh (script: "git log -n 1 --pretty=format:'%H'", returnStdout: true)
  }
  stage('Building'){
      sh "docker build -t my_app ."
  }
  stage('Launching'){
      sh "docker run -d my_app"
  }