Jenkins with Google Cloud Source Repository

喜你入骨 提交于 2019-12-05 01:56:40

Solution

You probably need to add a missing scope to the Compute Engine VM Instance running Jenkins that would give it access to Cloud Source Repository. You can follow the documentation or this steps, which ever you find convenient.

  1. Go to Cloud Deployment Manager
  2. Click on the name of the Jenkins deployment in question
  3. Click on the instance name in the left info pane and it will redirect you to VM instance details
  4. Stop the instance
  5. Press Edit and set the right access scope for Cloud Source Repository

After your start the VM instance, try adding your git repository again and once you select the credentials, either "Google Service Account from metadata" or from service account, everything should work properly.

Elaboration

I stumbled upon the "Invalid authentication credentials." issue while trying to add a Cloud Source Repository after deploying Jenkins from Launcher.

In my case the reason why it happened was that during the process of deployment the Cloud API access scope for Cloud Source Repositories on the Compute Engine VM instance was set to Disabled, which prevented any interaction from that instance even if a service account had all the necessary roles/permissions.

Here are the scopes that are reconfigured by Launcher:

scopes:
  - 'https://www.googleapis.com/auth/cloud.useraccounts.readonly'
  - 'https://www.googleapis.com/auth/devstorage.read_only'
  - 'https://www.googleapis.com/auth/logging.write'
  - 'https://www.googleapis.com/auth/monitoring.write'
  {% if enableComputeApi %}
  - 'https://www.googleapis.com/auth/compute'
  {% endif %}
  - 'https://www.googleapis.com/auth/cloudruntimeconfig'

Adding the following scope to the VM instance running Jenkins was enough to fix the error:

https://www.googleapis.com/auth/source.read_only 

Extra:

List of scopes for Google APIs.

I updated the plugin to 0.6 version. In 0.6 version, I have the same problem in Jenkins "Free-style" project. Bit I can success to checkout in Jenkins "pipeline" project. I just copy the "checkout syntax" in others project and replace 2 parts of the syntax to the right:

credentialsid -> replace to your right credentials id that you created Google Service Account from private key in jenkins. url ->replace to your google source repository url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!