栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

詹金斯管道中的sed

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

詹金斯管道中的sed

我建议在双引号中运行bash命令,并转义

$
字符。考虑以下Jenkins管道示例脚本:

#!/usr/bin/env groovypipeline {    agent any    stages {        stage('Build') { steps {     echo 'Inital content of temp.txt file'     sh 'cat temp.txt'     sh "sed -i ':a;N;$!ba;s/\n/\|\#\|/g' temp.txt"     echo 'Content of temt.txt file after running sed command...'     sh 'cat temp.txt' }        }    }}

temp.txt
我在此示例中使用的文件包含:

lorem ipsumdolor sit amet12 13 14test|test

当我运行它时,我得到以下控制台输出:

Started by user admin[Pipeline] nodeRunning on Jenkins in /var/jenkins_home/workspace/test-pipeline[Pipeline] {[Pipeline] stage[Pipeline] { (Build)[Pipeline] echoInital content of temp.txt file[Pipeline] sh[test-pipeline] Running shell script+ cat temp.txtlorem ipsumdolor sit amet12 13 14test|test[Pipeline] sh[test-pipeline] Running shell script+ sed -i :a;N;$!ba;s/n/|#|/g temp.txt[Pipeline] echoContent of temt.txt file after running sed command...[Pipeline] sh[test-pipeline] Running shell script+ cat temp.txtlorem ipsum|#|dolor sit amet|#||#|12 13 14|#||#|test|test|#|[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS

运行脚本

temp.txt
文件后,将其内容更改为:

lorem ipsum|#|dolor sit amet|#||#|12 13 14|#||#|test|test|#|

希望能帮助到你。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/485206.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号