Skip to main content

How to spawn remote docker container from a scripted jenkinsfile only by name of image

Comments

4 comments

  • Sven Scheil

    I found an answer why the sh commands are not executed in the remote container here https://go.cloudbees.com/docs/plugins/docker-workflow/

    "Unlike inside, shell steps inside the block are not run inside the container, but they could connect to it using a local TCP port for example.!

    It's the default behavior of image.withRun().

     

     

    0
  • Sven Scheil

    But still there is the question how to implement this scenario?

    We want to build jenkins jobs of type multibranch pipeline in containers and make use of jenkinsfile (preferrably of declarative jenkinsfile). These containers should be hosted independently (no container in container) of the jenkins-master on a remote docker host. The name of the image to spawn should be defined in the jenkinsfile in order to store it in the repository. We don't want to use these tedious image label feature of jenkins, because we don't want to update the labels in the jenkins gui for each new image we prepare.

     

    0
  • Denys Digtiar

    As you figured out in order for `sh` commands to run inside the container you need to use `inside`, not `withRun`. However, the `inside` and `build` commands do not work properly with remote Docker, see https://jenkins.io/doc/book/pipeline/docker/#using-a-remote-docker-server 

    It should probably be possible to let Docker do the work by writing the `Dockerfile` to do the build and then using `docker build`.

    0
  • Daniel Ritchie

    If you only want to ref the image, you will need to configure the other details.  We haven't used this (because we actually like to specify the details) but this is what you would need to pre-configure the other items so that you can ref the image directly:

    https://go.cloudbees.com/docs/plugins/docker-workflow/

    "this plugin provides a way to run build steps inside an arbitrary image. In the simplest case, just select an image and run your whole build inside it:"

    docker.image('maven:3.3.3-jdk-8').inside {
      git '…your-sources…'
      sh 'mvn -B clean install'
    }

     

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.