shell - 直接从 Git Repo 获取 Json 的所有键作为列表
问题描述
对于我的 Jenkins 管道,我想将 GitRepo 中的 Json 中的所有键填充为扩展选择参数。
[$class: 'ChoiceParameter', choiceType: 'PT_SINGLE_SELECT', description: 'Select an option', name: 'Option', randomName: 'choice-parameter-112', script: [$class: 'GroovyScript', fallbackScript: [classpath: [], sandbox: false, script: ''], script: [classpath: [], sandbox: false,
script: '''
//What should I write here in this block?
return keys
''']]]
基本上我只需要一个 curl 调用,我可以从上面的块中使用 Git 凭据 ID 从 Git 获取单个文件(我已将我的用户名和密码作为凭据 ID 存储在 Git 中)
解决方案
这是一个常见的情况,归结为:
除非您sh
有node
. 要拥有节点,您需要运行管道。要运行管道,您需要弄清楚参数。要找出这个参数,您需要调用sh
. 看到问题了吗?
为了克服这个问题,您可以通过在主管道之前运行另一个(小)管道来欺骗系统,例如
node('master') {
stage('read file') {
def file_contents = sh (returnStdout: true, script: "curl myrepo/myfile.json")
def parsed_data = readJSON text: file_contents
}
}
接着
properties([
parameters([
[$class: 'ChoiceParameter',
等等
推荐阅读
- node.js - NodeJs:Sequelize(版本 - 5+)N:M 关联不起作用
- php - 如何为 arangodb-php 中的流式事务增加“maxTransactionSize”
- python - Python:在对数刻度的两条曲线之间拟合圆,以连接圆的原点
- vue.js - VueJS PWA's - 通过 GenerateSW 启用 Workbox “调试”
- angular - 更新时共享变量值未“共享”
- azure-devops - 如何从动态发布中排除部署组目标
- c# - 在 MVC 数据列表中,在 SQL 查询中切换条件的最佳方法是什么
- java - 将 Iterable 与 List 进行比较会引发 NullPointerException
- blazor - Blazor,没有 ID 为“x”的跟踪对象。也许 DotNetObjectReference 实例已经被释放
- python - 在 python 环境中运行 Tesseract 或替代 OCR 模块,无需下载 .exe 文件