无法在 jenkins docker-agent 中使用 gcloud

Flo*_*uin 2 jenkins docker gcloud jenkins-pipeline

我正在尝试使用 docker 代理 (google/cloud-sdk:alpine) 运行 jenkins 管道,以将我的代码部署到 App Engine。不幸的是,尽管我是 docker 的 root,但我似乎没有权限这样做。

这个问题往往与这篇文章中的问题相同:Jenkins Pipeline gcloud issues in docker 但这个问题没有正确的答案。

当我手动启动这些命令时,一切正常。

我的詹金斯文件是:

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
                    '''
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

詹金斯的回报是:

[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
Run Code Online (Sandbox Code Playgroud)

小智 5

默认HOME=/


在 gcloud auth activate-service-account --key-file=${GCP_SA} 之前添加HOME=$WORKSPACE

为我工作