skip to Main Content

i have build a docker image and i can’t upload the image
the error i got is

[33m1 warning found (use docker --debug to expand):
[0m - StageNameCasing: Stage name 'BUILD_IMAGE' should be lowercase (line 1)
def COLOR_MAP = [
    'SUCCESS': 'good', 
    'FAILURE': 'danger',
]
pipeline {
    agent any
    tools {
        maven 'MAVEN3'
        jdk 'OracleJDK17'
    }
    environment {
        registryCredential = 'ecr:us-west-2:awscreds'
        appRegistry = "819764105945.dkr.ecr.us-west-2.amazonaws.com/vprofileappimg"
        vprofileRegistry = "https://819764105945.dkr.ecr.us-west-2.amazonaws.com"
    }
    stages {
        stage('Fetch Code'){
            steps {
                git branch: 'docker', url: 'https://github.com/infratute/baseline-vprofile-project-complete.git' 
            }
        }
        stage('Build') {
            steps {
                sh 'mvn install -DskipTests'
            }
            post{
                success {
                    echo "Now Archiving"
                    archiveArtifacts artifacts: '**/*.war'
                }
            }
        }
        stage('UNIT TEST') {
            steps {
                sh 'mvn test' 
            }
        }
        stage('Checkstyle Analysis') {
            steps {
                sh 'mvn checkstyle:checkstyle' 
            }
        }
        stage('Sonar Analysis') {
            environment {
                scannerHome = tool 'sonar4.7'
            }
            steps {
                withSonarQubeEnv('sonar') {
                   sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile 
                   -Dsonar.projectName=vprofile 
                   -Dsonar.projectVersion=1.0 
                   -Dsonar.sources=src/ 
                   -Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ 
                   -Dsonar.junit.reportsPath=target/surefire-reports/ 
                   -Dsonar.jacoco.reportsPath=target/jacoco.exec 
                   -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml'''
              }
               timeout(time: 3, unit: 'MINUTES') {
                    waitForQualityGate abortPipeline: true
                }
            }
        }
            
        stage('Build App Image') {
            steps {
       
                script {
                dockerImage = docker.build( appRegistry + ":$BUILD_NUMBER", "./Docker-files/app/multistage/")
             }

     }
    
    }
        stage('Upload App Image') {
            steps{
                script {
                docker.withRegistry( vprofileRegistry, registryCredential ) {
                    dockerImage.push("$BUILD_NUMBER")
                    dockerImage.push('latest')
                }
                }
            }
        }

    }
  
}

these were the code used
help me in fixing this errorenter image description here

enter image description here

need to upload the docker image in Amazon ecr

2

Answers


  1. The warning is a non-critical warning. Stage names in Docker should ideally be lowercase. While this doesn’t block your build, renaming the BUILD_IMAGE stage to lowercase is good practice. it’s not why your pipeline is failing

    are you sure that the ECR credentials correct and allows the job to push the image? and make sure about that the vprofileRegistry URL matches the exact ECR URL (with no typos or formatting issues).

    make sure that the credentials has this permission:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "ecr:GetAuthorizationToken",
            "ecr:BatchCheckLayerAvailability",
            "ecr:BatchGetImage",
            "ecr:PutImage",
            "ecr:InitiateLayerUpload",
            "ecr:UploadLayerPart",
            "ecr:CompleteLayerUpload"
          ],
          "Resource": "*"
        }
      ]
    }
    

    you can update the resource to your specific resource.

    Login or Signup to reply.
    • You need to check the first line of you Dockerfile. Dockerfile stage names are recommended to be lowercase to adhere to best practices and to avoid any potential issues.
    • Example:

    Change

    FROM ubuntu:latest AS BUILD_IMAGE
    # Your build instructions here
    

    to

    FROM ubuntu:latest AS build_image
    # Your build instructions here
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search