Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline templates - ability to specify the directory when cloning #190

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Templates/Common-Backend-Scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ CLI parameter | Description
-w `<workspace>` | **Workspace directory**, an absolute or relative path that represents unique directory for this pipeline definition, that needs to be consistent through multiple steps.
-r `<repoURL>` | **Git repository URL**, can either be SSH or HTTPS-based. Example: `-r git@github.com:Organization/MortgageApplication.git`
-b `<branch>` | **Git branch** that should be checked out. Example: `-b main`
-a `<application>` | (Optional) **Application name** to specify the directory into which git will clone. This is required for instance in the scenario if the repository name differs from the application name that is used in the build phase. Example: `-a CBSA`.

**Dealing with private repositories**

Expand Down
42 changes: 38 additions & 4 deletions Templates/Common-Backend-Scripts/gitClone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ Help() {
echo " -b <Branch> - Name of the Branch to be cloned. "
echo " Default=None, Required. "
echo " "
echo " Optional: "
echo " -a <Application> - Folder name to clone the "
echo " application git repo "
echo " "
echo " Ex: MortgageApplication "
echo " "
echo " Ex: refs/heads/main "
echo " "
exit 0
Expand Down Expand Up @@ -94,6 +100,7 @@ ERRMSG=""
Repo=""
WorkDir=""
Branch=""
application=""
HELP=$1

if [ "$HELP" = "?" ]; then
Expand Down Expand Up @@ -129,7 +136,7 @@ fi

# Get Options
if [ $rc -eq 0 ]; then
while getopts "h:r:w:b:" opt; do
while getopts "h:r:a:w:b:" opt; do
case $opt in
h)
Help
Expand All @@ -156,6 +163,17 @@ if [ $rc -eq 0 ]; then
fi
Workspace="$argument"
;;
a)
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
if [ -z "$argument" ] || [ "$nextchar" = "-" ]; then
rc=4
ERRMSG=$PGM": [WARNING] Application Name is required. rc="$rc
echo $ERRMSG
break
fi
application="$argument"
;;
b)
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
Expand Down Expand Up @@ -240,7 +258,11 @@ if [ $rc -eq 0 ]; then
echo $PGM": [INFO] ** Start Git Clone on HOST/USER: ${SYS}/${USER}"
echo $PGM": [INFO] ** Repo:" ${Repo}
echo $PGM": [INFO] ** WorkDir:" $(getWorkDirectory)
echo $PGM": [INFO] ** GitDir:" ${GitDir}
if [ ! -z "${application}" ]; then
echo $PGM": [INFO] ** GitDir:" ${application}
else
echo $PGM": [INFO] ** GitDir:" ${GitDir}
fi
echo $PGM": [INFO] ** Branch:" ${Branch} "->" ${BranchID}
echo $PGM": [INFO] **************************************************************"
echo ""
Expand Down Expand Up @@ -280,7 +302,15 @@ fi
if [ $rc -eq 0 ]; then

echo $PGM": [INFO] Preforming Git Clone of Repo ${Repo}, Branch ${BranchID} to $(getWorkDirectory)"
git clone -b ${BranchID} ${Repo} 2>&1
if [ ! -z "${application}" ]; then
CMD="git clone -b ${BranchID} ${Repo} ${application}"
else
CMD="git clone -b ${BranchID} ${Repo}"
fi

echo $PGM": [INFO] ${CMD}"
${CMD} 2>&1
rc=$?
rc=$?

if [ $rc -ne 0 ]; then
Expand All @@ -294,7 +324,11 @@ fi
# Check status of the cloned Repo
if [ $rc -eq 0 ]; then

cd ${GitDir}
if [ ! -z "${application}" ]; then
cd ${application}
else
cd ${GitDir}
fi
rc=$?

if [ $rc -eq 0 ]; then
Expand Down