[英]Bamboo Docker build Errors with Google Container Registry
[英]Jenkins Pipeline Build with Docker, Google Registry, and Google Auth Plugin
我正在使用 Jenkins 管道(使用由 JHipster 自動生成的管道腳本)構建 Docker 映像。 我想將我的最終 docker 鏡像推送到 Google Container Registry。
這是我所做的:
docker.build('us.gcr.io/[my-project-id]/[my-artifact-id]', 'target/docker')
(嗯。在項目符號后需要額外的文本行才能正確格式化)
docker.withRegistry('https://us.gcr.io', '[my-credential-id]') {
dockerImage.push 'latest'
}
但構建失敗:
ERROR: Could not find credentials matching [my-credential-id]
Finished: FAILURE
我基本上相信這些插件在管道世界中不起作用,但我想我會問是否有人已經完成了這一點並且可以給我一些指示。
嘗試在您的憑據 ID 前加上“gcr:”前綴。
您的憑據 ID 將類似於“gcr:[my-credential-id]”。
完整的工作示例:
stage('Build image') {
app = docker.build("[id-of-your-project-as-in-google-url]/[name-of-the-artifact]")
}
stage('Push image') {
docker.withRegistry('https://eu.gcr.io', 'gcr:[credentials-id]') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
請注意圖像的名稱。 在我用 [id-of-your-project-as-in-google-url]/[name-of-the-artifact] 符號命名圖像之前,我一直在努力推動圖像,即使有工作憑據也是如此。
當您收到需要啟用 Google ...... API 的消息時,您可能弄錯了 [id-of-your-project-as-in-google-url]。
圖像現在可以與 eu.gcr.io/[id-of-your-project-as-in-google-url]/[name-of-the-artifact]:47 的 url 一起使用。
LZ
以前的答案似乎不再適合我。 這是對我有用的語法:
stage('Push Image') {
steps {
script {
docker.withRegistry('https://gcr.io', 'gcr:my-credential-id') {
dockerImage.push()
}
}
}
}
設置谷歌雲注冊表的其他方式如下所示,您可以使用 withCredentials 插件並使用文件憑證類型。
withCredentials([file(credentialsId: 'gcr-private-repo-reader', variable: 'GC_KEY')]){
sh '''
chmod 600 $GC_KEY
cat $GC_KEY | docker login -u _json_key --password-stdin https://eu.gcr.io
docker ps
docker pull eu.gcr.io/<reponame>/<image>
'''
}
檢查您是否安裝了https://plugins.jenkins.io/google-container-registry-auth/插件。
插件安裝后使用gcr:credential-id
synthax
下面的答案以前並沒有完全起作用,現在顯然已被棄用。 由於歷史原因,我將文本留在這里。
我最終通過使用 gcloud 腳本階段代替 docker 管道階段繞過了這個問題,如下所示:
stage('publish gcloud') {
sh "gcloud docker -- push us.gcr.io/[my-project-id]/[my-artifact-id]"
}
gcloud 命令能夠找到使用gcloud init
在 Jenkins 服務器的命令行上設置的身份驗證憑據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.