shell - 如何通过shell(Jenkinsfile)中变量的给定模式获取单词?
问题描述
目前我面临一个问题,即如何从我的 Jenkinsfile 中的变量(Shell)中提取一些测试类的名称。
场景:每次在 Bitbucket 中创建拉取请求时,都会在 Jenkins 中激活流水线类型的作业,我可以在其中访问 Jenkinsfile 中名为“description”的变量。
例如,描述变量的输入可以包含以下内容:
US-2371 此处的任何描述 测试类:testclass1_tst,testclass_test 此处的任何其他描述。
预期输出:仅将以下内容保存在另一个变量中:testclass1_tst,testclass_test
注意:我需要用“,”分隔的测试类的名称,模式是那些以 tst、test、Test 结尾的测试类。
提前致谢。
参考:
解决方案
由于测试类:将出现在所有描述中,我们可以查找它并解析出类。
echo $description | sed -r 's/(.*Test Classes: )(\w.+)([[:space:]])(.*)/\2/
这会让你
testclass1_tst,testclass_test
推荐阅读
- php - mysqli_fetch_array 和 foreach 的解释
- css - 如何在使用 css 悬停在另一个元素上时公开 div 元素
- python - 使用将列表转换为 Dataframe 时遇到“Py4JJavaError”
- go - Go 变量名中大写缩写后的大写
- matlab - 如何在matlab中将矩阵分配给另一个矩阵的对角线
- javascript - 使用 for 循环、数组和 eventListener 更改输入元素的“名称”属性 - 无 jQuery
- php - Codeigniter - 使用控制器和方法创建函数循环表单
- java - 为什么我不能加载附加到引导类加载器搜索的资源?
- php - 如何从laravel 5.6中的重复外国ID中仅打印一条数据记录
- java - 如何测试转换器之类的东西