groovy - In Groovy - How to add comma in git tag list?
问题描述
I am doing git tag on a repo and getting below output.
command
def tagversion = sh(script:""" git tag --sort=v:refname """, returnStdout:true).trim()
Output:-
1.0
1.10.0
1.11.0
1.6
1.7
1.7.1
how can i add comma after each version?
expected output
1.0,
1.10.0,
1.11.0,
1.6,
1.7,
1.7.1
I have tried below code which works but add comma at last version as well and the entire list is showing as single string.
sh(script:""" git tag --sort=v:refname | tr '\n' ',' """, returnStdout:true).trim()
解决方案
sh
returns you a string, readLines()
will split it to an array, join
will put it back to string with some delimiter
sh(...).trim().readLines().join(',\n')
推荐阅读
- android - 无法在 QtCreator 中运行 android 应用程序
- qt - 从 QGridLayout 中检索 QSlider 子项
- mailchimp - Mailchimp api 不发送再见电子邮件 - 带有 https://github.com/drewm/mailchimp-api
- javascript - 在我的数组的每个对象中添加一个顶级列表
- python - 方法名不符合snake_case 命名风格
- javascript - 按下 keyup 和 keydown 时的图像变化
- javascript - Django - 为 Angular 应用程序提供服务
- mysql - 使用 Node.js 连接到 Google Cloud 上的 MySQL 数据库(错误:连接 ENOENT)
- pagination - 在没有查看器的情况下中继现代分页
- reporting-services - Reporting Services:为尚未识别的用户添加权限