Jenkins流水线推送Docker镜像至Artifactory Docker仓库失败求助
Your hunch about the missing repository path in the image tag is spot-on — this is the root cause of your "Not Found" error. Artifactory's Docker repositories have stricter tagging requirements compared to Amazon ECR, and skipping the repository key (docker_registry_repo) in your image name breaks the push workflow. Let's break down the fixes for both your original Docker pipeline and the Artifactory plugin approach.
1. Fixing the Native Docker Push Workflow
Artifactory requires Docker image tags to follow this format:
{artifactory-url}:{port}/{repository-key}/{image-name}:{tag}
Your original tag (artifactory.my.company.com:8443/test:latest) is missing the docker_registry_repo repository key, so Artifactory can't map the push to your target repository. Here's how to update your Jenkinsfile:
Option 1: Build the Image with the Full Artifactory Tag Upfront
pipeline { environment { jenkinsArtifactoryCredentialsID = '...' ARTIFACTORY_REGISTRY_BASE = 'https://artifactory.my.company.com:8443/artifactory/docker_registry_repo' IMAGE_NAME = 'test' } agent any options { skipStagesAfterUnstable() } stages { stage('Clone repository') { steps { script { checkout scm } } } stage('Build') { steps { script { // Build the image with the complete Artifactory-compatible tag image = docker.build("${ARTIFACTORY_REGISTRY_BASE}/${IMAGE_NAME}") } } } stage('Deploy to Artifactory') { steps { script { docker.withRegistry( ARTIFACTORY_REGISTRY_BASE, jenkinsArtifactoryCredentialsID ) { image.push('latest') image.push("${env.BUILD_NUMBER}") } } } } } }
Option 2: Retag the Image Before Pushing
If you prefer to keep the build stage clean, you can retag the image with the full repository path in the deploy stage:
stage('Deploy to Artifactory') { steps { script { def fullImagePath = "${ARTIFACTORY_REGISTRY_BASE}/${IMAGE_NAME}" // Retag the local image for Artifactory docker.image("test").tag("latest", fullImagePath) docker.image("test").tag("${env.BUILD_NUMBER}", fullImagePath) docker.withRegistry( ARTIFACTORY_REGISTRY_BASE, jenkinsArtifactoryCredentialsID ) { docker.image(fullImagePath).push('latest') docker.image(fullImagePath).push("${env.BUILD_NUMBER}") } } } }
2. Fixing the Artifactory Plugin (rtDockerPush) Workflow
When using the Artifactory plugin's rtDockerPush step, you don't need to include the full Artifactory URL in the image name — the plugin handles routing via the targetRepo parameter. Your mistake was including the Artifactory URL but omitting the repository key in the image tag. Here's the corrected approach:
stage('Deploy to Artifactory') { steps { script { // Push the latest tag rtDockerPush( serverId: 'company-artifactory', image: 'test:latest', targetRepo: 'docker_registry_repo' ) // Push the build number tag rtDockerPush( serverId: 'company-artifactory', image: "test:${env.BUILD_NUMBER}", targetRepo: 'docker_registry_repo' ) } } }
Make sure your Jenkins-configured Artifactory server has the base URL set to https://artifactory.my.company.com:8443/artifactory (not including the repository path) and that the credentials associated with company-artifactory have deploy permissions for docker_registry_repo.
Additional Troubleshooting Steps
- Validate Repository Permissions: In Artifactory, go to
Admin > Repositories > Repositories > docker_registry_repoand check the Deployment Policies to ensure your user hasAllow Deploypermissions. - Test Manual Push: On your Jenkins agent machine, run these commands to rule out infrastructure issues:
docker login artifactory.my.company.com:8443/artifactory/docker_registry_repo -u YOUR_USERNAME -p YOUR_PASSWORD/API_KEY docker tag test artifactory.my.company.com:8443/artifactory/docker_registry_repo/test:latest docker push artifactory.my.company.com:8443/artifactory/docker_registry_repo/test:latest - Verify Jenkins Credentials: Ensure your Jenkins credential is a Username with password type, using your Artifactory username and either your password or API key.
内容的提问来源于stack exchange,提问作者DocDriven

