3737
3838 if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
3939
40+ echo "Updating repo on SSH_REPOSITORY_REF=[${SSH_REPOSITORY_REF}]";
41+
4042 echo "********************************************";
4143
4244 git status;
5153
5254 git reset --hard;
5355
54- echo "Pulling any changes....";
56+ if [ "${SSH_REPOSITORY_REF}"=="tag" ]; then
57+
58+ echo "'tag' or nothing supplied for variable SSH_REPOSITORY_REF, fetching latest git tag to use.";
59+
60+ SSH_REPOSITORY_REF=$(git ls-remote --tags --sort=-v:refname git@${REPO_NAME_FULL} | sed 's#.*/##' | grep -v '\^{}' | head -n 1);
61+
62+ echo "Using SSH_REPOSITORY_REF=[${SSH_REPOSITORY_REF}]";
63+
64+ git checkout "${SSH_REPOSITORY_REF}"
65+
66+ else
67+
68+ echo "Pulling any changes....";
69+
70+ git pull --rebase
71+
72+ fi
5573
56- git pull --rebase
5774
5875 else
5976
@@ -160,6 +177,15 @@ spec:
160177
161178 echo "Clonning repo on branch=[${SSH_REPOSITORY_REF}]";
162179
180+ if [ "${SSH_REPOSITORY_REF}"=="tag" ]; then
181+
182+ echo "'tag' or nothing supplied for variable SSH_REPOSITORY_REF, fetching latest git tag to use.";
183+
184+ SSH_REPOSITORY_REF=$(git ls-remote --tags --sort=-v:refname git@${REPO_NAME_FULL} | sed 's#.*/##' | grep -v '\^{}' | head -n 1)
185+
186+ fi
187+
188+
163189 git clone -b "${SSH_REPOSITORY_REF}" git@${REPO_NAME_FULL} /git;
164190
165191 else
@@ -177,6 +203,8 @@ spec:
177203
178204 if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
179205
206+ echo "Updating repo on SSH_REPOSITORY_REF=[${SSH_REPOSITORY_REF}]";
207+
180208 echo "********************************************";
181209
182210 git status;
@@ -191,9 +219,25 @@ spec:
191219
192220 git reset --hard;
193221
194- echo "Pulling any changes....";
195222
196- git pull --rebase
223+ if [ "${SSH_REPOSITORY_REF}"=="tag" ]; then
224+
225+ echo "'tag' or nothing supplied for variable SSH_REPOSITORY_REF, fetching latest git tag to use.";
226+
227+ SSH_REPOSITORY_REF=$(git ls-remote --tags --sort=-v:refname git@${REPO_NAME_FULL} | sed 's#.*/##' | grep -v '\^{}' | head -n 1)
228+
229+ echo "Using SSH_REPOSITORY_REF=[${SSH_REPOSITORY_REF}]";
230+
231+ git checkout "${SSH_REPOSITORY_REF}"
232+
233+ else
234+
235+ echo "Pulling any changes....";
236+
237+ git pull --rebase
238+
239+ fi
240+
197241
198242 else
199243
@@ -204,6 +248,7 @@ spec:
204248
205249 fi
206250
251+
207252 echo "Finish init";
208253
209254 env :
0 commit comments