I successfully create docker images from my jenkinsfile pipeline on a slave, simply using the standard "sh" commands.
I want to try to pull the image from the docker / hub, and if it does not work (because it has not been saved there yet), create it and click on it in the docker hub.
Obviously, I somehow need to store the credentials for the docker hub and provide them with a docker login command.
My problem is that I am confused. There are plugins for connecting dockers, but I think they are designed to run jenkins steps inside a docker container, not what I'm trying to do. Also, many examples are most likely a script, not declarative.
In simple terms, “steps” I think I want to do something like
agent {
label 'pi'
}
steps {
sh 'docker login -u my-account -p xxxx'
sh 'docker pull my-account/image:version || (docker build -f dockerfile -t my-account/image:version && docker push my-account/image:version)'
....
}
but I also suspect that I may need to do something like
steps {
script {
withDockerRegistry([credentialsId: 'something', url: 'docker.io/my-account']) {
sh 'docker pull my-account/image:version || (docker build -f dockerfile -t my-account/image:version && docker push my-account/image:version)'
....
}
}
but I don’t want to make any mistakes and spin the pipeline, which currently works fine, except for this small amount.
Am I on the right?
source
share