groovy - sed command won't replace my string when executed form Jenkins
问题描述
I have a config.yml
file that contains the following:
access_key: ACC_KEY
secret_key: SEC_KEY
Now I am trying to replace the ACC_KEY
and SEC_KEY
with the actual access_key
ans secret_key
.
I have a groovy method that executes a shell script as given below:
def update(){
return this.execCmd("'sed -i s/ACC_KEY/${access_token}/g; s/SEC_KEY/${secret_token}/g' /root/.config/config.yml")
}
Is there something wrong in the way I have specified the sed
command inside the method? Because, whenever I run my Jenkins job, I am able to fetch the values of ${access_token}
and ${secret_token}
however it is not replacing ACC_KEY and SEC_KEY with those values.
解决方案
没有看到你拥有的整个 config.yml 就很难了。使用像这样的 config.yml 以及下面我所拥有的 groovy 方法应该可以满足您的需求!
配置.yml
config:
dockerfile: .woloxci/Dockerfile
project_name: some-project-name
services:
- postgresql
- redis
steps:
analysis:
- bundle exec rubocop -R app spec --format simple
- bundle exec rubycritic --path ./analysis --minimum-score 80 --no-browser
setup_db:
- bundle exec rails db:create
- bundle exec rails db:schema:load
test:
- bundle exec rspec
security:
- bundle exec brakeman --exit-on-error
audit:
- bundle audit check --update
environment:
RAILS_ENV: test
GIT_COMMITTER_NAME: a
GIT_COMMITTER_EMAIL: b
LANG: C.UTF-8
access_key: ACC_KEY
secret_key: SEC_KEY
参考:https ://jenkins.io/blog/2018/04/25/configuring-jenkins-pipeline-with-yaml-file/
Groovy 方法:
您可以在 Jenkins 中设置环境变量并像这样访问它们
println "access_key : ${env.access_key} , secret_key: ${secret_key}"
推荐阅读
- mysql - Cakephp 4 无法连接到远程数据源
- google-cloud-dataflow - apache beam 全局组合,在数据流上运行时管道启动后具有不可预测的行为
- flutter - 短信代码已过期。请重新发送验证码重试。扑
- python - 将代码从 Matlab 传递到 Python 值错误
- java - 在 Java 中使用 LDAPConnection 和端口 636
- javascript - 更改 jQuery DataTables 标题中的排序图标
- javascript - 如何检查输入事件的状态?
- flutter - 为什么可见性在颤振中不起作用?
- openssl - 签署企业社会责任证书
- php - 更新可变产品时自动为变体设置默认常规价格(自动批量编辑)