We've a containerized Jenkins pipeline and for one of the stages, some part of stage, we want to be executed on container and some on Jenkins master(which is Windows in our case) -
pipeline {
agent {
docker {
label "<node-name>"
image "<docker-image-path>"
}
}
stages {
stage('Testing') {
steps {
script {
//This below part will be executed on container
println "This below part will be executed on container"
sh '''pwd
hostname -i
'''
// Now want to execute below code on master which is Windows
println "Now want to execute below code on master which is Windows"
node('master') {
bat 'dir'
}
}
}
}
}
}
Part to be executed on container is executed successfully but code to execute on Windows Jenkins master fails with -
Cannot run program "docker" (in directory "C:\Jenkins\workspace\TestDocker"): CreateProcess error=2, The system cannot find the file specified
EDIT
And when I've docker installed on Windows machine, above error is not thrown but stucks there forever.
Could you please help me how I can execute code on node or container on demand?