Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63151

Execute steps before starting docker container

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Execute steps on the host, after selecting the proper node, and before starting the docker container.

      Minimal code examples (see the added pre directive):

      pipeline {
          agent {
              docker {
                  image 'maven:3-alpine'
                  pre {
                      echo 'Called from the host (outside the container).'
                  }
              }
          }
          stages {
              stage('Build') {
                  steps {
                      echo 'Called from inside the container.'
                  }
              }
          }
      }
      
      pipeline {
          agent none
          stages {
              stage('Build') {
                  agent {
                      docker {
                          image 'maven:3-alpine'
                          pre {
                              echo 'Called from the host (outside the container).'
                          }
                      }
                  }
                  steps {
                      echo 'Called from inside the container.'
                  }
              }
          }
      }
      

      The steps inside pre should be executed prior to executing the first stage/step.

      An alternative name is preRun.

       

        Attachments

          Activity

          95jonpet Peter Jonsson created issue -
          95jonpet Peter Jonsson made changes -
          Field Original Value New Value
          Summary Execute steps before starting docker cpmtaomer Execute steps before starting docker container
          95jonpet Peter Jonsson made changes -
          Description Execute steps on the host, after selecting the proper node, and before starting the docker container.

          Minimal code examples (see the added _pre_ directive):
          {code:java}
          pipeline {
              agent {
                  docker {
                      image 'maven:3-alpine'
                      pre {
                          echo 'Called from the host (outside the container).'
                      }
                  }
              }
              stages {
                  stage('Build') {
                      steps {
                          echo 'Called from inside the container.'
                      }
                  }
              }
          }
          {code}
          {code:java}
          pipeline {
              agent none
              stages {
                  stage('Build') {
                      agent {
                          docker {
                              image 'maven:3-alpine'
                              pre {
                                  echo 'Called from the host (outside the container).'
                              }
                          }
                      }
                      steps {
                          echo 'Called from inside the container.'
                      }
                  }
              }
          }
          {code}
          The steps inside _pre_ should be executed prior to executing the first stage/step.

           
          Execute steps on the host, after selecting the proper node, and before starting the docker container.

          Minimal code examples (see the added _pre_ directive):
          {code:java}
          pipeline {
              agent {
                  docker {
                      image 'maven:3-alpine'
                      pre {
                          echo 'Called from the host (outside the container).'
                      }
                  }
              }
              stages {
                  stage('Build') {
                      steps {
                          echo 'Called from inside the container.'
                      }
                  }
              }
          }
          {code}
          {code:java}
          pipeline {
              agent none
              stages {
                  stage('Build') {
                      agent {
                          docker {
                              image 'maven:3-alpine'
                              pre {
                                  echo 'Called from the host (outside the container).'
                              }
                          }
                      }
                      steps {
                          echo 'Called from inside the container.'
                      }
                  }
              }
          }
          {code}
          The steps inside _pre_ should be executed prior to executing the first stage/step.

          An alternative name is _preRun_.

           

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            95jonpet Peter Jonsson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: