我已经构建了一个 docker 镜像,但无法上传该镜像 我得到的错误是
\[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')
}
}
}
}
}
}
这些是使用的代码 帮助我修复此错误在此处输入图像描述
需要在Amazon ecr中上传docker镜像
该警告是非严重警告。 Docker 中的阶段名称最好是小写。虽然这不会阻止您的构建,但将 BUILD_IMAGE 阶段重命名为小写是一种很好的做法。这不是你的管道失败的原因
您确定 ECR 凭证正确并允许作业推送映像吗?并确保 vprofileRegistry URL 与确切的 ECR URL 匹配(没有拼写错误或格式问题)。
确保凭据具有此权限:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload"
],
"Resource": "*"
}
]
}
您可以将资源更新为您的特定资源。