Reputation: 71
I have a jenkins job where I am pushing the docker image in ECR. Please refer to the below code:
pipeline {
agent {
node {
label "${jenkins_node}"
}
}
tools {
maven 'maven 3.9.1'
}
stages {
stage('GIT checkout') {
steps {
dir("$WORKSPACE") {
checkout([$class : 'GitSCM',
branches : [[name: "${BRANCH}"]],
doGenerateSubmoduleConfigurations: false,
extensions : [[$class : 'SubmoduleOption',
disableSubmodules : false,
parentCredentials : true,
recursiveSubmodules: false,
reference : '',
timeout : 15,
trackingSubmodules : false]],
gitTool : 'Default',
submoduleCfg : [],
userRemoteConfigs : [[credentialsId: 'XXXXXXXXXX',
url : 'XXXXXXXXXXXX']]])
}
}
}
stage ('Prepare image tag name') {
steps {
script {
echo "image tag..."
IMAGE_TAG = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
echo "DEBUG: TAG name is $IMAGE_TAG"
}
}
}
stage('Build docker image') {
steps {
withAWS(roleAccount:'XXXXXXXXXXXX', role:'dcp-jenkins-role') {
sh '''
#!/bin/bash
set -x
cd $WORKSPACE
mvn clean install -DskipTests
'''
script{
sh """
sudo systemctl start docker
sudo chmod 777 /var/run/docker.sock
aws ecr get-login-password --region us-east-1 | docker login --username XXXX --password-stdin XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com
docker build -t XXXXXXXXXXXXXX:$IMAGE_TAG .
docker tag XXXXXXXXXXXXXX:$IMAGE_TAG XXXXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/XXXXXXXXXXXXXX:$IMAGE_TAG
docker push XXXXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/XXXXXXXXXXXXXX:$IMAGE_TAG
"""
}
}
}
}
When I am running my jenkins job at first attempt, it is throwing below error:
When I am running the job again, it is successfully getting completed without any error. This is happening frequently and I am running my jenkins jobs on slave node.
Upvotes: 0
Views: 422