Skip to content
Open
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
33 changes: 33 additions & 0 deletions hooks/jira-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
CLIENTHOOKURL="https://raw.githubusercontent.com/egovenrments/CIOps/master/hooks/jira-hook"
read -p "Enter Your Local Git Workspace Path : " GIT_CHECKOUT_PATH
GITWORKINGDIR=$(realpath ${GIT_CHECKOUT_PATH})
read -p "Enter Your Jira Project Key : " X
if [ ! -d ${GITWORKINGDIR} ]
then
echo "[ Error ] ${GITWORKINGDIR} directory does not exists, please enter the complete path of the git workspace."
exit 1
fi
if [ ! -d ${GITWORKINGDIR}/.git ]
then
echo "[ Error ] ${GITWORKINGDIR} is not a git repository."
exit 1
else
originUrl=`git --git-dir=${GITWORKINGDIR}/.git config --get remote.origin.url`
REPO_BARE_NAME=`echo ${originUrl} | awk -F '/' {'print \$NF'}`
fi
echo "Remote Repository : ${originUrl}"
echo "[ Info ] Enforcing the hooks policy, Please wait..."
rm -rf ${GITWORKINGDIR}/.git/hooks/commit-msg
wget -q -O ${GITWORKINGDIR}/.git/hooks/commit-msg ${CLIENTHOOKURL}
if [ $? != 0 ]
then
echo "[ Error ] Unable to apply the hooks to ${GITWORKINGDIR}, please check the permission ..."
echo "Please contact your DevOps team."
rm -rf ${GITWORKINGDIR}/.git/hooks/commit-msg > /dev/null 2>&1
exit 1;
else
chmod +x ${GITWORKINGDIR}/.git/hooks/commit-msg
sed -i "4,5 s/WAP/$X/" ${GITWORKINGDIR}/.git/hooks/commit-msg
echo "[ Success ] Hooks has been applied for ${GIT_CHECKOUT_PATH}"
fi
47 changes: 47 additions & 0 deletions hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
# hook identifies jira ids in branch names, adds on more goodies if we are a hotifx or release branch and attempts to prevent blank commit messages...although this needs a bit more work...


COMMIT_FILE=$1
COMMIT_MSG=$(cat $1)

#First and foremost check whether the commit message is blank. if so then abort the commit. strip any spaces out too
#this one only works at present when someone tries to do git commit -m "" or git commit -m " "
#if anyone uses tools such as sourcetree, then these GUIs typically present a prompt...eg. "do you want to commit wihtout a message" and pass in optional attributes to git commit to allow this.

if [[ -z "${COMMIT_MSG// }" ]]; then
echo "You cannot have an empty commit message. Please enter something meaningful!"
exit 1
fi


#if we get to this point then prepend different things onto our commit message...
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
#CURRENT_BRANCH="hotfix/jira-123"

##try identify a jira ticket number, and also uppercase it
JIRA_ID=$(echo "$CURRENT_BRANCH" | tr 'a-z' 'A-Z' | grep -Eo "[A-Z]+-[0-9]+")
HOTFIX_ID=$(echo "$CURRENT_BRANCH" | tr 'a-z' 'A-Z' | grep -Eo "HOTFIX")
RELEASE_ID=$(echo "$CURRENT_BRANCH" | tr 'a-z' 'A-Z' | grep -Eo "RELEASE")

#if we have no jira then use current branch name instead
if [ [-z "$JIRA_ID"] ];then
JIRA_ID=$CURRENT_BRANCH
fi


if [ ! -z "$HOTFIX_ID" ]; then
echo "[$JIRA_ID] [HOTFIX]: $COMMIT_MSG" > $COMMIT_FILE
echo "JIRA ID '$JIRA_ID' AND HOTFIX, matched in current branch name, prepended BOTH to commit message."

elif [ ! -z "$RELEASE_ID" ]; then
echo "[$JIRA_ID] [RELEASE]: $COMMIT_MSG" > $COMMIT_FILE
echo "RELEASE branch found. '[RELEASE]' prepended to commit message."

elif [[ ! -z "$JIRA_ID" ]]; then
echo "[$JIRA_ID]: $COMMIT_MSG" > $COMMIT_FILE
echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)"

else
echo "[$CURRENT_BRANCH]: $COMMIT_MSG" > $COMMIT_FILE
fi
14 changes: 7 additions & 7 deletions vars/buildPipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ spec:
valueFrom:
secretKeyRef:
name: jenkins-credentials
key: gitReadAccessToken
key: gitReadAccessToken
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /root/.docker
- name: kaniko-cache
mountPath: /cache
mountPath: /cache
resources:
requests:
memory: "1792Mi"
cpu: "750m"
limits:
memory: "3954Mi"
memory: "4080Mi"
cpu: "1500m"
- name: git
image: docker.io/egovio/builder:2-64da60a1-version_script_update-NA
Expand All @@ -52,7 +52,7 @@ spec:
- name: kaniko-cache
persistentVolumeClaim:
claimName: kaniko-cache-claim
readOnly: true
readOnly: true
- name: jenkins-docker-cfg
projected:
sources:
Expand All @@ -66,7 +66,7 @@ spec:
node(POD_LABEL) {

def scmVars = checkout scm
String REPO_NAME = env.REPO_NAME ? env.REPO_NAME : "docker.io/upyogio";
String REPO_NAME = env.REPO_NAME ? env.REPO_NAME : "docker.io/{{DOCKER_ACCOUNT}}";
String GCR_REPO_NAME = "asia.gcr.io/digit-egov";
def yaml = readYaml file: pipelineParams.configFile;
List<JobConfig> jobConfigs = ConfigParser.parseConfig(yaml, env);
Expand Down Expand Up @@ -127,7 +127,7 @@ spec:
--destination=${image} \
--destination=${gcr_image} \
--no-push=${noPushImage} \
--cache-repo=upyogio/cache/cache
--cache-repo={{DOCKER_ACCOUNT}}/cache/cache
"""
echo "${image} and ${gcr_image} pushed successfully!!"
}
Expand All @@ -142,7 +142,7 @@ spec:
--snapshotMode=time \
--destination=${image} \
--no-push=${noPushImage} \
--cache-repo=upyogio/cache/cache
--cache-repo={{DOCKER_ACCOUNT}}/cache/cache
"""
echo "${image} pushed successfully!"
}
Expand Down
8 changes: 3 additions & 5 deletions vars/deployer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ spec:
command:
- cat
tty: true
env:
- name: "GOOGLE_APPLICATION_CREDENTIALS"
value: "/var/run/secret/cloud.google.com/service-account.json"
volumeMounts:
env:
volumeMounts:
- name: kube-config
mountPath: /root/.kube
resources:
Expand All @@ -26,7 +24,7 @@ spec:
limits:
memory: "256Mi"
cpu: "200m"
volumes:
volumes:
- name: kube-config
secret:
secretName: "${pipelineParams.environment}-kube-config"
Expand Down
2 changes: 1 addition & 1 deletion vars/jobBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
name: jenkins-credentials
key: dockerPassword
- name: DOCKER_NAMESPACE
value: upyogio
value: {{DOCKER_ACCOUNT}}
- name: DOCKER_GROUP_NAME
value: dev
resources:
Expand Down