diff --git a/integration/Jenkinsfile b/integration/Jenkinsfile index d9814085f..7f64641c0 100644 --- a/integration/Jenkinsfile +++ b/integration/Jenkinsfile @@ -1,12 +1,14 @@ +import java.util.Random + pipeline { agent none options { buildDiscarder logRotator( - daysToKeepStr: '16', - numToKeepStr: '10' - ) + daysToKeepStr: '16', + numToKeepStr: '10' + ) } parameters { string(name: 'VERSION', defaultValue: '', description: 'Version') @@ -53,6 +55,9 @@ pipeline { cleanWs() stopAndRemoveDockers() setupWorkspace() + retryWithBackoff(3) { + dockerLogin() + } } } stage('Install NATIVE pkg') { @@ -111,6 +116,9 @@ pipeline { cleanWs() stopAndRemoveDockers() setupWorkspace() + retryWithBackoff(3) { + dockerLogin() + } } } stage('Install RPM pkg') { @@ -166,6 +174,9 @@ pipeline { cleanWs() stopAndRemoveDockers() setupWorkspace() + retryWithBackoff(3) { + dockerLogin() + } } } stage('Install Docker') { @@ -226,6 +237,9 @@ pipeline { cleanWs() stopAndRemoveDockers() setupWorkspace() + retryWithBackoff(3) { + dockerLogin() + } } } stage('Install Docker FIPS') { @@ -284,7 +298,7 @@ def void stopAndRemoveDockers() { sh ''' for container_id in $(docker ps -a -q);do docker stop $container_id;done for container_id in $(docker ps -a -q);do docker rm $container_id;done - docker system prune --force --volumes + docker system prune --all --force --volumes volumes=$(docker volume ls -qf dangling=true) if [ "$volumes" ]; then docker volume rm $volumes @@ -308,4 +322,30 @@ def void printNodeInfo() { socket.connect(InetAddress.getByName("8.8.8.8"), 10002); nodeIp = socket.getLocalAddress().getHostAddress(); println("The Node IP Address is: ${nodeIp}") +} + +def void dockerLogin() { + withDockerRegistry([credentialsId: "DockerHub", url: ""]) { + sh 'docker login' + } +} + +def void retryWithBackoff(int retries, Closure body) { + int attempt = 0 + Random random = new Random() + while (attempt < retries) { + try { + body.call() + return + } catch (Exception e) { + attempt++ + if (attempt >= retries) { + throw e + } + int randomDelay = random.nextInt(15) // Random delay between 0 and 15 seconds + int backoffTime = 30 + randomDelay // Base backoff of 30 seconds plus random delay + println("Retry attempt ${attempt}, sleeping for ${backoffTime} seconds") + sleep time: backoffTime, unit: 'SECONDS' + } + } } \ No newline at end of file diff --git a/jenkins/artifacts/jenkinsfile b/jenkins/artifacts/jenkinsfile index 325cdb258..f906566bc 100644 --- a/jenkins/artifacts/jenkinsfile +++ b/jenkins/artifacts/jenkinsfile @@ -384,7 +384,7 @@ def void stopAndRemoveDockers() { rm -rf /opt/home/nightly/ mkdir -p /opt/home/nightly/ for container_id in $(docker ps -a -q);do docker stop $container_id;done - docker system prune --force --volumes + docker system prune --all --force --volumes volumes=$(docker volume ls -qf dangling=true) if [ "$volumes" ]; then docker volume rm $volumes