1、shell 替换属性文件内容:
sed -i "s#^key=.*#key=value#g" propertiesPath
如:
sed -i "s#^user.name=.*#user.name=用户名#g" path/demo.properties
sed -i "s#^user.password=.*#user.password=密码#g" path/demo.propertie
2、 在JenkinsFile里面,有时候有对项目的properties文件进行环境配置
pipeline {
agent any
stages {
stage('configEnv') {
steps {
sh 'sed -i "s#^user.name=.*#user.name=用户名#g" path/demo.properties'
}
}
}
}
2.1 多行
pipeline {
agent any
stages {
stage('configEnv') {
steps {
sh '''
#comment 注释
sed -i "s#^user.name=.*#user.name=用户名#g" path/demo.properties
sed -i "s#^user.password=.*#user.password=密码#g" path/demo.properties
'''
}
}
}
}
2.2 替换内容有引号的情况,要进行两次转义
pipeline {
agent any
stages {
stage('configEnv') {
steps {
sh '''
#comment 注释
sed -i "s#^user.name=.*#user.name=用户名#g" path/demo.properties
sed -i "s#^user.password=.*#user.password=密码#g" path/demo.properties
sed -i "s#^\\"user.password\\":.*#\\"user.password\\":\\"root\\"#g" path/otherFile
'''
}
}
}
}
标签:sed,name,sh,user,Linux,path,password,properties
来源: https://blog.csdn.net/weixin_42713970/article/details/86511642