Use Docker Pipeline Plugin without interactive mode

Viewed 1487

I'm trying to use docker with Jenkins Scripted pipeline, and faced with several problems.

If I use it in sh docker ... it results in an error

command not found docker

  1. I tried to fix it by changing Install setting in Global Configuration tool - but not succeed with it.

  2. I'm trying to use Docker plugin now.

def run_my_stage(String name, String cmd, String commit) {
return {
    stage(name) {
        node("builder") {
                docker.withRegistry("192.168.1.33:5000") {
                    def myimg = docker.image("my-img")
                    sh "docker pull ${myimg.imageName()}"
                    sh "docker run ${cmd}"
                }
            }
        }
}

Where cmd == --user=\$UID --rm -t -v ./build/:/home/user/build 192.168.1.33:5000/my-img

I use this code for parallel stages (list of stages generated dynamically), and got this error

java.net.MalformedURLException: no protocol: 192.168.1.33:5000

What is proper usage of this plugin? I found a lot of examples with withRun and other methods from docker, but I don't need to run any commands inside this image, I have command in Dockerfile (so it built-in for my container).

3 Answers

You are missing the protocol, the registry must be https://192.168.1.33:5000

The error itself has the answer :).

java.net.MalformedURLException: no protocol: 192.168.1.33:5000

You are missing protocol in custom registry. Refer https://jenkins.io/doc/book/pipeline/docker/#custom-registry

def run_my_stage(String name, String cmd, String commit) {
return {
    stage(name) {
        node("builder") {
                docker.withRegistry("https://192.168.1.33:5000") {
                    def myimg = docker.image("my-img")
                    sh "docker pull ${myimg.imageName()}"
                    sh "docker run ${cmd}"
                }
            }
        }
}

Also I have problem with relative path, but simple fix with adding pwd before relative path to build fixed.

Thx @yzT

Related