简体   繁体   English

无法在 jenkins docker-agent 中使用 gcloud

[英]Unable to use gcloud in a jenkins docker-agent

I'm trying to run a jenkins pipeline with a docker agent (google/cloud-sdk:alpine) to deploy my code to App Engine.我正在尝试使用 docker 代理 (google/cloud-sdk:alpine) 运行 jenkins 管道,以将我的代码部署到 App Engine。 Unfortunately, it seams I have no permission to to that although I'm root in the docker.不幸的是,尽管我是 docker 的根,但我似乎没有权限这样做。

The issue tends to be the same as in this post: Jenkins Pipeline gcloud problems in docker But there is no right answer to this issue.这个问题往往与这篇文章中的问题相同: Jenkins Pipeline gcloud problems in docker但是这个问题没有正确的答案。

When I launch theses command by hand, everything works.当我手动启动这些命令时,一切正常。

My Jenkinsfile is:我的詹金斯文件是:

pipeline {
    agent {
        docker { 
            image 'registry.hub.docker.com/google/cloud-sdk:alpine' 
            args '-v $HOME:/home -w /home'    
        }
    }
    stages {
        stage('Deploy') {
            steps {
                withCredentials([file(credentialsId: 'bnc-hub', variable: 'SECRET_JSON')]) {
                    sh '''
                    set +x
                    gcloud auth activate-service-account --key-file $SECRET_JSON
                    gcloud config set project bnc-hub
                    gcloud app deploy app.yaml
                    '''
                }
            }
        }
    }
}

The return in Jenkins is:詹金斯的回报是:

[workspace] Running shell script
+ set +x
WARNING: Could not setup log file in /.config/gcloud/logs, (Error: Could not create directory [/.config/gcloud/logs/2018.12.28]: Permission denied.
Please verify that you have permissions to write to the parent directory.)
script returned exit code 1

By default HOME=/默认首页=/

Add添加
HOME=$WORKSPACE before gcloud auth activate-service-account --key-file=${GCP_SA} HOME=$WORKSPACE before gcloud auth activate-service-account --key-file=${GCP_SA}

worked for me为我工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM