Jenkins 与 Google Cloud 源存储库

2024-03-11

我正在尝试使用 Jenkins 进行 CI/CD。 我开发了一个Python Flask 应用程序。我正在将此应用程序部署到 Google App Engine 中。到目前为止我正在使用gcloud app deploy app.yaml将应用程序部署到 Google App Engine 的命令。

此应用程序的代码存在于 Google Cloud Source Repository 中。

由于 git(Google Cloud Source Repository) 的身份验证需要 Google OAuth,所以我安装了Google OAuth 凭据插件 https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin

现在我面临两个问题

  1. When I use "Google Service Account from metadata" Credential Kind, I am not seeing the credentials listed in "Source Code Management". See screenshot
  2. 当我使用“私钥中的 Google 服务帐户”时,我能够看到凭据。但是当我运行我的詹金斯工作时,我收到以下错误

致命:无法呼叫 com.google.jenkins.plugins.source.GoogleRobotUsernamePassword.writeObject() : 序列化失败 com.google.jenkins.plugins.source.GoogleRobotUsernamePasswordModule$ForRemote#credentials 上课 com.google.jenkins.plugins.source.GoogleRobotUsernamePasswordModule$ForRemote ---- 调试信息 ---- 消息:无法调用 com.google.jenkins.plugins.source.GoogleRobotUsernamePassword.writeObject() 原因异常:java.lang.RuntimeException 原因消息: 序列化失败 com.google.jenkins.plugins.source.GoogleRobotUsernamePasswordModule$ForRemote#credentials 上课 com.google.jenkins.plugins.source.GoogleRobotUsernamePasswordModule$ForRemote ------------------------------- java.lang.UnsupportedOperationException:拒绝封送 出于安全原因,org.joda.time.DateTime;看https://jenkins.io/redirect/class-filter/ https://jenkins.io/redirect/class-filter/在 hudson.util.XStream2$BlacklistedTypesConverter.marshal(XStream2.java:543) 在 com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69) 在 com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58) 在 com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)

Question:如何在 Jenkins 中验证 Google Cloud Source 存储库?在 Jenkins 中使用 Google Cloud Source 存储库需要哪些步骤|插件?


Solution

您可能需要向运行 Jenkins 的 Compute Engine 虚拟机实例添加缺失的范围,以使其能够访问 Cloud Source Repository。您可以按照文档 https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes或此步骤,您觉得方便即可。

  1. Go to 云部署管理器 https://pantheon.corp.google.com/dm/deployments
  2. 单击相关 Jenkins 部署的名称
  3. 单击左侧信息窗格中的实例名称,它会将您重定向到VM instance details
  4. Stop实例
  5. Press Edit并为Cloud Source Repository设置正确的访问范围

启动 VM 实例后,尝试再次添加 git 存储库,一旦选择凭据(“来自元数据的 Google 服务帐户”或来自服务帐户),一切都应该正常工作。

阐述

我偶然发现了“无效的身份验证凭据”。部署后尝试添加云源存储库时出现问题来自 Launcher 的 Jenkins https://console.cloud.google.com/launcher/details/click-to-deploy-images/jenkins?q=jenkins.

就我而言,发生这种情况的原因是在部署过程中云API访问范围 https://cloud.google.com/compute/docs/access/service-accounts#accesscopesiam对于云源存储库在 Compute Engine 虚拟机实例上被设置为Disabled,即使服务帐户拥有所有必要的角色/权限,也会阻止该实例的任何交互。

以下是 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'

添加以下内容scope https://developers.google.com/identity/protocols/googlescopes#sourcerepov1运行 Jenkins 的 VM 实例足以修复错误:

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

Extra:

Google API 的范围列表。 https://developers.google.com/identity/protocols/googlescopes

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jenkins 与 Google Cloud 源存储库 的相关文章

随机推荐

  • Core Data NSPredicate 按实体类过滤?

    我将如何创建一个NSPredicate按类实体过滤Contact 解决方案为NSPredicate 检查对象类的种类 https stackoverflow com a 8065935 242933崩溃 NSPredicate predic
  • 标头中没有 no-cors 时无法获取 POST

    在提出这样的请求时 return fetch http localhost 8000 login method POST headers new Headers Content Type application json Accept ap
  • 如何以编程方式知道 NodeJS 应用程序何时内存不足

    我如何知道我的应用程序内存不足 对我来说 我在服务器上进行一些视频转码 有时会导致内存不足错误 因此 我希望知道应用程序何时耗尽内存 以便我可以立即终止视频转码器 谢谢 您可以看到内置的内存正在使用多少process module cons
  • Swift NSTimer 动态改变间隔[重复]

    这个问题在这里已经有答案了 如何更改 NSTimer 上的时间间隔 var difficulty Double 1 0 override func viewDidLoad super viewDidLoad NSTimer schedule
  • Blazor - 动态改变角色

    我有一个 blazor 应用程序 在页面中我使用以下代码根据当前用户角色显示一些部分
  • 如何为按钮的按下状态设置不同的颜色?

    我有一些Buttons在我的 Android 应用程序上 它们有图标和文本 我可以设置a的背景颜色Button在java代码中 如果单击该按钮 我想以不同的颜色显示 那么 如何为按下状态设置不同的颜色Button
  • HTML2PDF 字符集中有 æøå 字符

    content html2pdf new HTML2PDF P A4 en html2pdf gt writeHTML content false html2pdf gt Output S 给我一个带有 的 PDF 文件 我检查了 html
  • 更改应用栏的颜色

    我试图理解 两者之间有什么区别Toolbar Appbar ActionBar 我正在尝试将 AppBar 或其他任何内容的颜色更改为红色 有人提到尝试更改主题 我尝试过 但不知道有什么区别 而且我也是 Android 编程新手 所以如果你
  • 我应该将 _method=PUT/DELETE 存储在帖子中还是网址中

    我正在使用 ASP NET MVC 构建 RESTful Web 应用程序 并计划通过 POST 传输 PUT 和 DELETE 请求 因为这似乎是最实用的解决方法 我想知道的是 我是否应该像这样通过 url 传输信息
  • 可以将选项添加到 npm package.json 依赖项中吗?

    我对 sqlite3 包有依赖性 默认情况下 安装时 sqlite3 软件包会下载并使用 sqlite3 引擎的预打包版本 使用 sqlite3 扩展时有时会出现问题 因此可以选择使用以下命令安装它 npm install build fr
  • 填充其父项的 ListBoxItem

    我正在开发一个 Windows Phone 应用程序 我有以下 XAML
  • 将相对路径转换为绝对路径?

    我不确定这些路径是否重复 给定相对路径 如何使用 shell 脚本确定绝对路径 Example relative path x y a b z c d absolute path a b c d 我在unix中遇到的最可靠的方法是readl
  • 为什么不能在 Slick 中使用已编译的 Insert 语句

    狡猾的专家 我正在学习和使用 Slick 我有一个问题 文档说编译查询仅适用于选择 更新和删除 http slick typesafe com doc 2 0 0 queries html compiled queries http sli
  • Spark DataFrame 重新分区:未保留的分区数

    根据 Spark 1 6 3 的文档 repartition partitionExprs Column 应保留结果数据框中的分区数量 返回按给定分区划分的新 DataFrame 保留现有分区数量的表达式 取自https spark apa
  • 无法启动模拟器:错误:模拟器在 60 秒内未连接

    我无法使用 VSCode for Flutter 进行调试 我正在使用 Windows 并且正在尝试使用 Android 模拟器 我尝试重新安装 Flutter Android SDK 和 VSCode 来解决该问题 并尝试设置环境变量 这
  • 恢复 C# Windows 窗体背景色

    我在 Windows 窗体窗体上有一个按钮 我将其背景颜色更改为Color Yellow当它被点击时 当再次单击它时 我想将其恢复为原始默认外观 默认背景色是SystemColor Control 当第一次单击按钮时 我唯一改变的是 btn
  • iOS 的标准语法解析器是什么?

    iPad 和 iPhone 的 iOS 支持解析器吗 特别是 lex yacc 或 flex bison 是否可用于 iOS 开发 xcode4 有原生支持的库吗 我可以通过 lex yacc 生成语法 然后获取 c 文件并将它们放入我的项
  • 在当前正在写入的文件上创建 FileInfo 是否安全?

    在我的应用程序 C 4 5 winforms 应用程序 中 我定期检查文件夹的内容并将找到的任何文件的详细信息存储到数据库中 在此例程中 我创建了一个FileInfo实例使用new FileInfo path 我读了属性CreationTi
  • 使用 Apache POI 读取 excel 文件

    我创建了这段代码来使用 Apache POI 读取 excel 文件的内容 我使用 eclipse 作为编辑器 但是当我运行代码时 我在粗体行中遇到了问题 有什么问题 excel的内容如下 Emp ID Name Salary 1 0 jo
  • Jenkins 与 Google Cloud 源存储库

    我正在尝试使用 Jenkins 进行 CI CD 我开发了一个Python Flask 应用程序 我正在将此应用程序部署到 Google App Engine 中 到目前为止我正在使用gcloud app deploy app yaml将应