Jenkins 与 jFrog Artifactory 推送 Docker 图像

Jenkins with jFrog Artifactory push Docker images

我正在尝试在 Jenkins 中配置新管道。我已经在 Windows 服务器上购买并安装了 jFrog artifactory pro,它已经启动并且 运行 位于:https://artifactory.mycompany.com

我在这里找到了这个样本: https://github.com/jfrog/project-examples/blob/master/jenkins-examples/pipeline-examples/declarative-examples/docker-push-example/Jenkinsfile

更具体地说,这一部分:

stage ('Push image to Artifactory') {
        steps {
            rtDockerPush(
                serverId: "ARTIFACTORY_SERVER",
                image: ARTIFACTORY_DOCKER_REGISTRY + '/hello-world:latest',
                // Host:
                // On OSX: "tcp://127.0.0.1:1234"
                // On Linux can be omitted or null
                host: HOST_NAME,
                targetRepo: 'docker-local',
                // Attach custom properties to the published artifacts:
                properties: 'project-name=docker1;status=stable'
            )
        }
    }

它正在构建和创建 docker 图像,但是当它开始推送图像时,它无法推送图像并出现错误。不确定下面应该放什么:

我在 artifactory "docker-local" 中创建了一个新的本地存储库。尝试省略主机并获得

"Unsupported OS".

使用 "host: 'tcp://IP ADDRESSS" 或 "artifactory.mycompany.com:80/artifactory" 将主机放回生成

"Unsupported protocol scheme"

如何配置 jenkins 管道以与 jFrog artifactory 一起工作?

找到解决方案:

  • ARTIFACTORY_DOCKER_REGISTRY 应该是 IP/Artifactory-Repo-Key/Image:Tag
  • HOST 应该是 docker 守护程序(windows 的 Docker 是 localhost:2375)

        stage('Build image') { // build and tag docker image
            steps {
                echo 'Starting to build docker image'
    
                script {
                    def dockerfile = 'Dockerfile'
                    def customImage = docker.build('10.20.111.23:8081/docker-virtual/hello-world:latest', "-f ${dockerfile} .")
    
                }
            }
        }
    
        stage ('Push image to Artifactory') { // take that image and push to artifactory
            steps {
                rtDockerPush(
                    serverId: "jFrog-ar1",
                    image: "10.20.111.23:8081/docker-virtual/hello-world:latest",
                    host: 'tcp://localhost:2375',
                    targetRepo: 'local-repo', // where to copy to (from docker-virtual)
                    // Attach custom properties to the published artifacts:
                    properties: 'project-name=docker1;status=stable'
                )
            }
        }