[英]Pipeline syntax: append to an existing file without using sh ""
I'm trying to manipulate a terraform.tfvars file during deploy.我正在尝试在部署期间操作terraform.tfvars文件。
Code:代码:
dir("test123/${params.serviceName}/terraform"){
sh """
#!/bin/bash -e
cat <<EOF > ./terraform.tfvars
remote_data = [{
vpc_state = "${params.targetEnv}/vpc/terraform.state"
ecs_state = "${params.targetEnv}/ecs/terraform.state"
bucket = "${ENV_BUCKET}"
region = "${REGION}"
}]
The above lines of code are ugly.上面的代码行很难看。 Is there an alternative way, such as using
readFile
function in groovy or anything else beside calling sh
function Thanks是否有替代方法,例如在 groovy 中使用
readFile
函数或除了调用sh
函数之外的任何其他方法谢谢
I think there might be solutions with other terraform features depending on your version, I'm struggling to see why this can't be solved by normal variables.我认为根据您的版本,可能有其他 terraform 功能的解决方案,我正在努力了解为什么普通变量无法解决这个问题。 Have you tried loading them via environment variables instead?
您是否尝试过通过环境变量加载它们? You would just define the variables in the tfvars, and then they'd be supplied via TF_VARS_ENV_BUCKET like here .
您只需在 tfvars 中定义变量,然后通过 TF_VARS_ENV_BUCKET 提供它们, 就像这里。 You could just write the job params directly to envs to make sure they're present.
您可以直接将作业参数写入 envs 以确保它们存在。
Found a more elegant way:找到了更优雅的方式:
def remoteData(deploymentDir){
def data = """
remote_data = [{
vpc_state = "${TARGET_ENV}/vpc/terraform.state"
ecs_state = "${TARGET_ENV}/ecs/terraform.state"
bucket = "${ENV_BUCKET}"
region = "${ENV_BUCKET_REGION}"
}]
consul_address="${CONSUL_ADDRESS}"
vault_address="${VAULT_ADDRESS}"
service_name="${SERVICE_NAME}"
image_tag="${IMAGE_TAG}"
region="${REGION}"
deploy_role="${ARN}"
dashboard_folder="${SERVICE_NAME}-${TARGET_ENV}"
"""
writeFile file: "${WORKSPACE}/${deploymentDir}/terraform.tfvars", text: "${data}"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.