24 lines
818 B
Groovy
24 lines
818 B
Groovy
def call(Map args = [:]) {
|
|
script {
|
|
if (!args.imageName || !args.registry || !args.credentialsId) {
|
|
error "dockerPush requires imageName, registry, and credentialsId arguments"
|
|
}
|
|
|
|
def imageName = args.imageName
|
|
def registry = args.registry
|
|
def credentialsId = args.credentialsId
|
|
|
|
withCredentials([usernamePassword(
|
|
credentialsId: credentialsId,
|
|
usernameVariable: 'DOCKER_USER',
|
|
passwordVariable: 'DOCKER_PASS'
|
|
)]) {
|
|
echo "Logging into Docker registry: ${registry}"
|
|
sh "echo \$DOCKER_PASS | docker login ${registry} -u \$DOCKER_USER --password-stdin"
|
|
|
|
echo "Pushing Docker image: ${imageName}"
|
|
sh "docker push ${args.registry}/${imageName}"
|
|
}
|
|
}
|
|
}
|