<p>I have the below pipeline. </p>

<pre><code>pipeline {
    agent any

    environment {
        PROJECT_ID = "*****"
        IMAGE = "gcr.io/$PROJECT_ID/node-app"
        BRANCH_NAME_NORMALIZED = "${BRANCH_NAME.toLowerCase().replace(" / ", "
        _ ")}"
    }

    stages {
        stage('Build') {
            steps {
                sh ' docker build -t ${IMAGE}:${BRANCH_NAME_NORMALIZED} . '

            }
        }
        stage('Push') {
            steps {
                withCredentials([file(credentialsId: 'jenkins_secret', variable: 'GC_KEY')]) {
                    sh("gcloud auth activate-service-account --key-file=${GC_KEY}")
                }
                sh ' gcloud auth configure-docker  '
                sh ' docker push $IMAGE:${BRANCH_NAME_NORMALIZED} '
            }
        }
        stage('Deploy') {
            steps {
                withDockerContainer(image: "gcr.io/google.com/cloudsdktool/cloud-sdk", toolName: 'latest') {
                    withCredentials([file(credentialsId: 'jenkins_secret', variable: 'GC_KEY')]) {
                        sh("gcloud auth activate-service-account --key-file=${GC_KEY}")
                        sh("gcloud container clusters get-credentials k8s --region us-central1 --project ${DEV_PROJECT}")
                        sh("kubectl get pods")

                    }
                }
            }
        }
    }
}
</code></pre>

<p>In Deploy stage it gives the following error : </p>

<blockquote>
  <p>gcloud auth activate-service-account --key-file=****
  WARNING: Could not setup log file in /.config/gcloud/logs, (Error: Could not create directory [/.config/gcloud/logs/2020.02.05]: Permission denied.</p>
  
  <p>Please verify that you have permissions to write to the parent directory.)
  ERROR: (gcloud.auth.activate-service-account) Could not create directory [/.config/gcloud]: Permission denied.
  Please verify that you have permissions to write to the parent directory.</p>
</blockquote>

<p>I can't understand where this command wants to create a directory, docker container or in Host machine? 
Have you got any similar problem ? </p>

Amir Damirov
<p>A better approach would be to <a href="https://stackoverflow.com/questions/48531688/login-to-gke-via-service-account-with-token">Login to GKE via Kubernetes service account with token</a> and using a kubeconfig file instead of activating a google service account. </p>

<p>This has several advantages including Kubernetes RBAC support, controlling blast radius should your credentials be compromised, etc. You can read more about <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/" rel="nofollow noreferrer">using RBAC Authorization</a> here. </p>
