Setting labels for windows docker and linux docker to be seperate

Currently on my setup I have windows and linux agents that can both create and run docker images (windows docker images and linux docker images repectivly). I know I can limit which label to run docker builds on but can I set it such that if the build I’m running uses a windows docker image to run on windows node and the same with linux? right now I have them labeled as linux-docker and windows-docker but it doesn’t seem I can simply do

agent {
    label agent_label
    docker {
        image docker_label
    }
}

There is this mentioned in the docs for this specific case: Using Docker with Pipeline

That’s what I was talking about, it doesn’t solve the problem because I want to run docker on both windows AND linux and specifically windows containers (which can’t run on linux)

so if I try and run a windows docker build and if it targets a linux machine it’ll fail and vice versa

you could use isUnix and check if the agent is windows or linux

docker.image(isUnix() ? "fooimage1" : "bazimage2").inside { }

declarative should work too, I havn’t tested it

docker { image "${isUnix() ? "fooimage1" : "fooimage2"}" }

but i’m not sure isUnix will work that early

Can this change what agent it’s running on?

I’m confused. I thought you wanted a solution for which image is used on which agent. If you want to control which agent to use, you want to specify that.

 agent {
    label 'docker&&linux'
    docker {
          image 'node:14.17'
    }
 }

(probably)

1 Like