Difference between revisions of "Command Center SSH Bitbucket"
Line 137: | Line 137: | ||
− | + | == Create a new Custom Data Source == |
|
− | + | Once the scripts have been created, make the scripts accessible to Command Center by adding the directory as a new Custom Data Source |
|
+ | * When naming the Custom Data Source consider using a name that will make it easily identifiable as to what repository and branch the Custom Data Source is pointing towards. |
||
− | Command Center by adding the directory as a new Custom Data Source |
||
− | + | * There will be one Custom Data source created for a single repo/branch used by Command Center |
|
+ | ** If two branches from the same repository are required, there will be two Custom Data Sources Required. |
||
− | make it easily identifiable as to what repository and branch the |
||
− | Custom Data Source is pointing towards. |
||
− | - There will be one Custom Data source created for a single |
||
− | repo/branch used by Command Center |
||
− | - If two branches from the same repository are required, there will |
||
− | be two Custom Data Sources Required. |
||
− | + | == Leveraging the Custom Data Source from Command Center == |
|
− | + | At this point, when the Command Center Project is created, simply select the Custom Data Source as the Data Source Credential and you should be all set. |
|
− | select the Custom Data Source as the Data Source Credential and you |
||
− | should be all set. |
Revision as of 15:06, 4 February 2025
- clone.sh
- USER_NAME
- REPO
- BRANCH_NAME
- pull.sh
- BRANCH_NAME
- pushfiles.sh
- No modification needed
Add the contents below to each of the respective files, being sure to update the user_name/repo/branch where indicated.
Contents
clone.sh
**Be sure to supply the USER_NAME, REPO, BRANCH where indicated** #!/bin/bash REPO="ssh://git@bitbucket.org/<USER_NAME>/<REPO>.git" BRANCH="BRANCH_NAME" echo "Using credential: ${CREDENTIAL_NAME}" echo "==================================================================" echo "Custom Clone Incoming variables:" echo "" echo " CUSTOM_DIR = ${CUSTOM_DIR}" echo " WORKSPACES_DIR = ${WORKSPACES_DIR}" echo " WORKSPACE_NAME = ${WORKSPACE_NAME}" echo " REPO = ${REPO}" echo " BRANCH = ${BRANCH}" echo "User running git clone is $(whoami)" # For Debugging GIT_SSH_COMMAND="ssh" git clone "$REPO" "$WORKSPACES_DIR/$WORKSPACE_NAME" ret=$? echo "Clone return status $ret" if [ $ret -ne 0 ] ; then exit 1 fi # This use case only occurs when a clone was done prior and the branch was different from the desired one cur_branch="$(git rev-parse --abbrev-ref HEAD)" if [ "${cur_branch}" != "${BRANCH}" ] ; then echo "Branch was ${cur_branch} so switching to ${BRANCH}" git switch "${BRANCH}" else echo "Branch already at ${cur_branch}, no need to switch " fi cd ~/ || exit 1 exit 0
pull.sh
**Be sure to supply the branch where indicated** #!/bin/bash BRANCH="BRANCH_NAME" echo "Using credential: ${CREDENTIAL_NAME}" echo "==================================================================" echo "" echo "Custom Pull Incoming variables:" echo " CUSTOM_DIR = ${CUSTOM_DIR}" echo " CLIENT_SOURCE_DIR = ${CLIENT_SOURCE_DIR}" echo " BRANCH = ${BRANCH}" echo "User running git pull is $(whoami)" # For Debugging cd "${CLIENT_SOURCE_DIR}" || exit 1 GIT_SSH_COMMAND="ssh" git --git-dir="$CLIENT_SOURCE_DIR/.git" --work-tree="$CLIENT_SOURCE_DIR" pull ret=$? echo "Pull return status $ret" if [ $ret -ne 0 ] ; then exit 1 fi # This use case only occurs when a clone was done prior and the branch was different from the desired one cur_branch="$(git rev-parse --abbrev-ref HEAD)" if [ "${cur_branch}" != "${BRANCH}" ] ; then echo "Branch was ${cur_branch} so switching to ${BRANCH}" git switch "${BRANCH}" else echo "Branch already at ${cur_branch}, no need to switch " fi cd ~/ || exit 1 exit 0
pushfiles.sh
#!/bin/bash echo "Using credential: ${CREDENTIAL_NAME}" echo "==================================================================" echo "CUSTOM_PUSH_FILES (${PUSH_TYPE})" echo "" echo "Custom Push Files Incoming variables:" echo " CUSTOM_DIR = ${CUSTOM_DIR}" echo " CLIENT_SOURCE_DIR = ${CLIENT_SOURCE_DIR}" echo " IMPORT_MESSAGE = ${IMPORT_MESSAGE}" echo " IMPORT_LIST_PATH = ${IMPORT_LIST_PATH}" echo "User running pushfiles is $(whoami)" # run script cd "${CLIENT_SOURCE_DIR}" || exit 1 echo "Files to import to the repo are: " cat "${IMPORT_LIST_PATH}" while IFS= read -r f; do git add "$f" ret=$? echo "Push add status $ret" if [ $ret -ne 0 ] ; then exit 1 fi done < "${IMPORT_LIST_PATH}" git commit -m "${IMPORT_MESSAGE}" GIT_SSH_COMMAND="ssh" git push ret2=$? echo "Push return status $ret2" if [ $ret2 -ne 0 ] ; then exit 1 fi cd ~/ || exit 1 exit 0
Create a new Custom Data Source
Once the scripts have been created, make the scripts accessible to Command Center by adding the directory as a new Custom Data Source
- When naming the Custom Data Source consider using a name that will make it easily identifiable as to what repository and branch the Custom Data Source is pointing towards.
- There will be one Custom Data source created for a single repo/branch used by Command Center
- If two branches from the same repository are required, there will be two Custom Data Sources Required.
Leveraging the Custom Data Source from Command Center
At this point, when the Command Center Project is created, simply select the Custom Data Source as the Data Source Credential and you should be all set.