Skip to content

Commit 46a8f35

Browse files
committed
Persist the Preview URL for future jobs
Having the Preview URL available could be useful to run other checks on the Preview, for example an a11y audit. Here's how to use the persisted file that contains the URL into another job: steps: - attach_workspace: # Must be absolute path or relative path from working_directory at: /tmp/workspace - run: | if [[ `cat /tmp/workspace/preview-url` == "http://preview-url.com" ]]; then echo "It worked!"; else echo "Nope!"; exit 1 fi Of course the job that wants to use the Preview URL needs to require this orb to run into a previous step before it to start (using require). Here's more info: https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
1 parent cf0a7b9 commit 46a8f35

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

source.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ jobs:
9696
echo "export SUBDOMAIN=`echo $CIRCLE_BRANCH | shasum | awk '{print $1}' | head -c 6`" >> $CIRCLE_BUILD_NUM
9797
echo "export CONTAINER=$CIRCLE_PROJECT_REPONAME-\$BRANCH" >> $CIRCLE_BUILD_NUM
9898
echo "export DIRECTORY=$CIRCLE_PROJECT_REPONAME/\$BRANCH" >> $CIRCLE_BUILD_NUM
99+
- run:
100+
name: Write Preview URL to a persisted file
101+
command: |
102+
source $CIRCLE_BUILD_NUM
103+
mkdir -p workspace
104+
echo "https://$SUBDOMAIN.<< parameters.domain >>" > workspace/preview-url
99105
- run:
100106
name: Notify Preview Deploy Started
101107
command: |
@@ -141,3 +147,7 @@ jobs:
141147
ssh << parameters.user >>@<< parameters.server >> "docker ps | grep $CIRCLE_PROJECT_REPONAME | grep -vE '`cat grep_regex`'" | awk '{print $2}' > old_containers
142148
ssh << parameters.user >>@<< parameters.server >> "docker rm -f "`cat old_containers`""
143149
ssh << parameters.user >>@<< parameters.server >> "rm -fr "`cat old_containers | sed "s/$CIRCLE_PROJECT_REPONAME-/$CIRCLE_PROJECT_REPONAME\//g"`""
150+
- persist_to_workspace:
151+
root: workspace
152+
paths:
153+
- preview-url

0 commit comments

Comments
 (0)