jenkins - How do I replace a specific line in a file, using jenkins file build step?
问题描述
I am running a Jenkinsfile that needs to include a step, where it goes in to an existing file in a Github repo and updates a line with a version number variable, that is stored a Jenkins credential called ${version}. So that when the build is done, the variable version is added in to the compilede go program.
e.g
The Jenkins Step will need to go in to the version.go file, go to the fmt.Println() line and add in ${version}.
stage('Update Version number in version.go') {
sh 'echo "${version}" > Version.go'
}
File and line to be updated. Example of what I need the println line to look like.
Version.go
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of CLI",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println( **${version}** )
},
}
I've been able to test adding ${version} to an existing file. My main confusion is how to specify a location in an existing file.
Thanks
解决方案
推荐阅读
- c# - AddSingleton(S, T) 代替 AddSingleton(T) 的好处
- php - 如何重定向以从原始网址缩短网址?
- c - 赋值运算符在 C 程序中的 if 语句中作为条件工作正常
- python-3.x - 在 python 3.x 中执行 curl 命令是否有任何修改?
- python-3.x - 执行Nuitka编译的*.exe程序时如何隐藏cmd控制台?
- react-hooks - 无法在反应挂钩中单击按钮时绑定单选按钮和复选框数据
- python - 计算一系列火炬张量的均值和标准差
- reactjs - 条件渲染的差异(React)
- python - 我需要删除熊猫中满足条件的行
- sql-server - 我们可以在 SQL 视图中添加 NoLock