github.com/jaylevin/jenkins-library@v1.230.4/documentation/docs/steps/dockerExecute.md (about)

     1  # ${docGenStepName}
     2  
     3  ## ${docGenDescription}
     4  
     5  ## ${docGenParameters}
     6  
     7  ## Kubernetes support
     8  
     9  If the Jenkins is setup on a Kubernetes cluster, then you can execute the closure inside a container of a pod by setting an environment variable `ON_K8S` to `true`. However, it will ignore `containerPortMappings`, `dockerOptions` and `dockerVolumeBind` values.
    10  
    11  ## ${docGenConfiguration}
    12  
    13  ## ${docJenkinsPluginDependencies}
    14  
    15  ## Side effects
    16  
    17  none
    18  
    19  ## Exceptions
    20  
    21  none
    22  
    23  ## Pulling images in an non-anonymous way
    24  
    25  !!! warning "Credentials are stored by default unencrypted on disk"
    26      When accessing a docker registry with credentials for pulling
    27      images your credentials for access the docker registry
    28      are stored in plain text on disk for a short amount of time.
    29      There will be a corresponding log message with level "warning" in
    30      the job log.
    31      In order to avoid having the credentials written to disk, you
    32      should configure a password helper. The log message mentioned
    33      previously contains a link to a page explaining how a password helper
    34      can be configured.
    35      Having the credentials written to disk is not recommended.
    36      In addition, we don't recommend using personalised accounts for CI but rather dedicated "technical" users.
    37  
    38  ## Example 1: Run closure inside a docker container
    39  
    40  ```groovy
    41  dockerExecute(dockerImage: 'maven:3.5-jdk-7'){
    42      sh "mvn clean install"
    43  }
    44  ```
    45  
    46  ## Example 2: Run closure inside a container in a kubernetes pod
    47  
    48  ```sh
    49  # set environment variable
    50  export ON_K8S=true"
    51  ```
    52  
    53  ```groovy
    54  dockerExecute(script: this, dockerImage: 'maven:3.5-jdk-7'){
    55      sh "mvn clean install"
    56  }
    57  ```
    58  
    59  In the above example, the `dockerEcecute` step will internally invoke [dockerExecuteOnKubernetes](dockerExecuteOnKubernetes.md) step and execute the closure inside a pod.
    60  
    61  ## Example 3: Run closure inside a container which is attached to a sidecar container (as for example used in [seleniumExecuteTests](seleniumExecuteTests.md)
    62  
    63  ```groovy
    64  dockerExecute(
    65          script: script,
    66          containerPortMappings: [containerPortMappings:'selenium/standalone-chrome':[containerPort: 4444, hostPort: 4444]],
    67          dockerImage: 'node:8-stretch',
    68          dockerName: 'node',
    69          dockerWorkspace: '/home/node',
    70          sidecarImage: 'selenium/standalone-chrome',
    71          sidecarName: 'selenium',
    72  ) {
    73      git url: 'https://github.com/XXXXX/WebDriverIOTest.git'
    74      sh '''npm install
    75            node index.js
    76      '''
    77  }
    78  ```