Skip to content

Commit 82e2bd0

Browse files
authored
Merge pull request #99 from cloudfoundry-community/bgandon/interpolate-text-file
Interpolate the content of `text file`
2 parents 3f8dd17 + c6fb21b commit 82e2bd0

5 files changed

+42
-2
lines changed

out

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fi
7272

7373
export TEXT_FILE_CONTENT=""
7474
[[ -n "${text_file}" && ! -f "${text_file}" ]] && text_file=""
75-
[[ -n "${text_file}" && -f "${text_file}" ]] && TEXT_FILE_CONTENT="$(cat "${text_file}")"
75+
[[ -n "${text_file}" && -f "${text_file}" ]] && TEXT_FILE_CONTENT="$(envsubst < "${text_file}")"
7676

7777
ATTACHMENTS_FILE_CONTENT=""
7878
[[ -n "${attachments_file}" && -f "${attachments_file}" ]] && ATTACHMENTS_FILE_CONTENT="$(cat "${attachments_file}")"

test/all.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export BUILD_TEAM_NAME='main'
4444
webhook_url='https://some.url'
4545
base_text=":some_emoji:<https://my-ci.my-org.com/teams/main/pipelines/my-pipeline/jobs/my-job/builds/my-build|Alert!>"
4646
sample_text="This text came from sample.txt. It could have been generated by a previous Concourse task.\n\nMultiple lines are allowed.\n"
47+
env_vars_tail="BUILD_NAME=my-build\nVERSION=1.0.1\nQUALITY_GATE=B (ERROR)\nWITH_PIPE=<something>\nwith_GLOB=./path/to/*.jar\n"
4748
missing_text="_(no notification provided)_"
4849

4950
username="concourse"
@@ -60,6 +61,9 @@ test combined_text_template_and_file | jq -e "
6061
( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and
6162
( .body | keys | length == 7 )"
6263

64+
test combined_text_template_and_file_with_vars | jq -e "
65+
.body.text == \"${base_text}\n${sample_text}\n${env_vars_tail}\"
66+
"
6367

6468
test combined_text_template_and_file_empty | jq -e "
6569
.webhook_url == $(echo $webhook_url | jq -R .) and
@@ -110,6 +114,10 @@ test text_file | jq -e "
110114
( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and
111115
( .body | keys | length == 7 )"
112116

117+
test text_file_with_env_vars | jq -e "
118+
.body.text == \"${sample_text}\n${env_vars_tail}\"
119+
"
120+
113121
test text_file_empty | jq -e "
114122
.webhook_url == $(echo $webhook_url | jq -R .) and
115123
.body.channel == null and
@@ -203,4 +211,4 @@ test env_file | jq -e "
203211
.body.attachments[1].text == \"<something> - ./path/to/*.jar\" and
204212
( .body.attachments | length == 2 )"
205213

206-
echo -e '\e[32;1m'"All tests passed!"'\e[0m'
214+
echo -e '\e[32;1m'"All tests passed!"'\e[0m'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"params": {
3+
"text_file": "sample-with-vars.txt",
4+
"text": ":some_emoji:<https://my-ci.my-org.com/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME|Alert!>\n$TEXT_FILE_CONTENT\n",
5+
"env_file": ".env",
6+
"username": "concourse",
7+
"debug": "true"
8+
},
9+
"source": {
10+
"url": "https://some.url"
11+
}
12+
}

test/sample-with-vars.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This text came from sample.txt. It could have been generated by a previous Concourse task.
2+
3+
Multiple lines are allowed.
4+
5+
BUILD_NAME=${BUILD_NAME}
6+
VERSION=${VERSION}
7+
QUALITY_GATE=$QUALITY_GATE
8+
WITH_PIPE=${WITH_PIPE}
9+
with_GLOB=$with_GLOB

test/text_file_with_env_vars.out

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"params": {
3+
"text_file": "sample-with-vars.txt",
4+
"env_file": ".env",
5+
"username": "concourse",
6+
"debug": "true"
7+
},
8+
"source": {
9+
"url": "https://some.url"
10+
}
11+
}

0 commit comments

Comments
 (0)