Skip to content

Instantly share code, notes, and snippets.

@parnurzeal
Last active August 29, 2015 13:59
Show Gist options
  • Save parnurzeal/10811308 to your computer and use it in GitHub Desktop.
Save parnurzeal/10811308 to your computer and use it in GitHub Desktop.
#!/bin/bash
COMMAND=$1
PARAM1=$2
PARAM2=$3
PARAM3=$4
curl "http://dev-agspchef105z.dev.jp.local:8080/job/gspope-chef-repo/buildWithParameters?OBJECT=$COMMAND&PARAM1=$PARAM1&PARAM2=$PARAM2&PARAM3=$PARAM3"
<File>
[alias]
commitpushbump = "!f(){ git commit -m \"$1 $2\" && git push origin master && curl -q 'http://192.168.50.3:8080/git/notifyCommit?url=ssh://[email protected]:7999/bddcheflab/theeraphol-chef-repo.git' && echo Please do \"git pull\" to get version bump update from Jenkins' }; f"
pbump = "!f(){ git push origin master && curl -q 'http://192.168.50.3:8080/git/notifyCommit?url=ssh://[email protected]:7999/bddcheflab/theeraphol-chef-repo.git' && echo Please do \"git pull\" to get version bump update from Jenkins' }; f"
<Commands>
git config alias.commitpushbump \"!f(){ git commit -m \"$1 $2\" && git push origin master && curl -q 'http://192.168.50.3:8080/git/notifyCommit?url=ssh://[email protected]:7999/bddcheflab/theeraphol-chef-repo.git' && echo Please do \"git pull\" to get version bump update from Jenkins' }; f"
git config alias.pbump \"!f(){ git push origin master && curl -q 'http://192.168.50.3:8080/git/notifyCommit?url=ssh://[email protected]:7999/bddcheflab/theeraphol-chef-repo.git' && echo Please do \"git pull\" to get version bump update from Jenkins' }; f"
git checkout master
COOKBOOK=`git log -1 --pretty=%s | awk '{print $1}'`
VERSION=`git log -1 --pretty=%s | awk '{print $2}'`
# In case, Jenkins commit merge before build
if [ "$COOKBOOK" == "Merge" ] ; then
COOKBOOK=`git log -2 --pretty=%s | tail -1 | awk '{print $1}'`
VERSION=`git log -2 --pretty=%s | tail -1 | awk '{print $2}'`
fi
echo "Receiving parameter: COOKBOOK=$COOKBOOK VERSION=$VERSION"
if [ $VERSION -eq "" ] ; then
echo "No specified version. Starting bump $COOKBOOK (patch version) ..."
knife spork bump git-cookbook
else
echo "Starting bump $COOKBOOK to $VERSION ..."
knife spork bump git-cookbook manual $VERSION
fi
knife spork upload git-cookbook
git add "cookbooks/$COOKBOOK/metadata.rb"
git commit -m "[Jenkins] Finished bumping $COOKBOOK to $VERSION"
git push origin master
git checkout master
OBJECT=`git log -1 --pretty=%s | awk '{print $1}'`
PARAM1=`git log -1 --pretty=%s | awk '{print $2}'`
PARAM2=`git log -1 --pretty=%s | awk '{print $3}'`
PARAM3=`git log -1 --pretty=%s | awk '{print $4}'`
# In case, Jenkins commit merge before build
if [ "$OBJECT" == "Merge" ] ; then
OBJECT=`git log -2 --pretty=%s | tail -1 | awk '{print $1}'`
PARAM1=`git log -2 --pretty=%s | tail -1 | awk '{print $2}'`
PARAM2=`git log -2 --pretty=%s | tail -1 | awk '{print $3}'`
PARAM3=`git log -2 --pretty=%s | tail -1 | awk '{print $4}'`
fi
echo "Receiving parameter: OBJECT=$OBJECT PARAM1=$PARAM1 PARAM2=$PARAM2 PARAM3=$PARAM3"
if [ "$OBJECT" == "cookbook" ] ; then
if [ "$PARAM2" == "" ] ; then
echo "No specified version. Starting bump $COOKBOOK (patch version) ..."
knife spork bump $PARAM1
else
echo "Starting bump $PARAM1 to $PARAM2 ..."
knife spork bump $PARAM1 manual $PARAM2
fi
knife spork upload $PARAM1
git add "cookbooks/$PARAM1/metadata.rb"
git commit -m "[Jenkins] Finished bumping $PARAM1 to $PARAM2"
git push origin master
elif [ "$OBJECT" == "role" ] ; then
knife role from file $PARAM1
echo "Uploaded role $PARAM1"
elif [ "$OBJECT" == "environment" ] ; then
knife environment from file $PARAM1
MSG="Uploaded environment $PARAM1"
elif [ "$OBJECT" == "run_list" ] ; then
if [ "$PARAM1" == "add" ] || [ "$PARAM1" == "remove" ] || [ "$PARAM1" == "set" ] ; then
echo "$PARAM1 runlist $PARAM2 $PARAM3"
knife node run_list $PARAM1 $PARAM2 "$PARAM3"
MSG="knife node run_list $PARAM1 $PARAM2 $PARAM3"
fi
else
echo "No correct command"
exit 1
fi
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>ssh://[email protected]:7999/bddcheflab/theeraphol-chef-repo.git</url>
<credentialsId>80041a02-67b5-490c-8d10-1a9237b43ffd</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions>
<hudson.plugins.git.extensions.impl.WipeWorkspace/>
</extensions>
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers>
<hudson.triggers.SCMTrigger>
<spec></spec>
<ignorePostCommitHooks>false</ignorePostCommitHooks>
</hudson.triggers.SCMTrigger>
</triggers>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>git checkout master
OBJECT=`git log -1 --pretty=%s | awk &apos;{print $1}&apos;`
PARAM1=`git log -1 --pretty=%s | awk &apos;{print $2}&apos;`
PARAM2=`git log -1 --pretty=%s | awk &apos;{print $3}&apos;`
PARAM3=`git log -1 --pretty=%s | awk &apos;{print $4}&apos;`
# In case, Jenkins commit merge before build
if [ &quot;$OBJECT&quot; == &quot;Merge&quot; ] ; then
OBJECT=`git log -2 --pretty=%s | tail -1 | awk &apos;{print $1}&apos;`
PARAM1=`git log -2 --pretty=%s | tail -1 | awk &apos;{print $2}&apos;`
PARAM2=`git log -2 --pretty=%s | tail -1 | awk &apos;{print $3}&apos;`
PARAM3=`git log -2 --pretty=%s | tail -1 | awk &apos;{print $4}&apos;`
fi
echo &quot;Receiving parameter: OBJECT=$OBJECT PARAM1=$PARAM1 PARAM2=$PARAM2 PARAM3=$PARAM3&quot;
if [ &quot;$OBJECT&quot; == &quot;cookbook&quot; ] ; then
if [ &quot;$PARAM2&quot; == &quot;&quot; ] ; then
echo &quot;No specified version. Starting bump $COOKBOOK (patch version) ...&quot;
knife spork bump $PARAM1
else
echo &quot;Starting bump $PARAM1 to $PARAM2 ...&quot;
knife spork bump $PARAM1 manual $PARAM2
fi
knife spork upload $PARAM1
git add &quot;cookbooks/$PARAM1/metadata.rb&quot;
git commit -m &quot;[Jenkins] Finished bumping $PARAM1 to $PARAM2&quot;
git push origin master
elif [ &quot;$OBJECT&quot; == &quot;role&quot; ] ; then
knife role from file $PARAM1
echo &quot;Uploaded role $PARAM1&quot;
elif [ &quot;$OBJECT&quot; == &quot;environment&quot; ] ; then
knife environment from file $PARAM1
MSG=&quot;Uploaded environment $PARAM1&quot;
elif [ &quot;$OBJECT&quot; == &quot;run_list&quot; ] ; then
if [ &quot;$PARAM1&quot; == &quot;add&quot; ] || [ &quot;$PARAM1&quot; == &quot;remove&quot; ] || [ &quot;$PARAM1&quot; == &quot;set&quot; ] ; then
echo &quot;$PARAM1 runlist $PARAM2 $PARAM3&quot;
knife node run_list $PARAM1 $PARAM2 &quot;$PARAM3&quot;
MSG=&quot;knife node run_list $PARAM1 $PARAM2 $PARAM3&quot;
fi
fi
</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers>
<hudson.plugins.ansicolor.AnsiColorBuildWrapper plugin="[email protected]">
<colorMapName>xterm</colorMapName>
</hudson.plugins.ansicolor.AnsiColorBuildWrapper>
</buildWrappers>
</project>
#!/bin/bash -l
# trigger by curl -i 'http://dev-gspachef105z.dev.jp.local:8080/job/gspope-chef-repo/buildWithParameters?OBJECT=cookbook&PARAM1=...&PARAM2=...&PARAM3=...'
git checkout master
echo "Receiving parameter: OBJECT=$OBJECT PARAM1=$PARAM1 PARAM2=$PARAM2 PARAM3=$PARAM3"
if [ "$OBJECT" == "cookbook" ] ; then
if [ "$PARAM1" == "" ] ; then
echo "No specified cookbook."
exit 1
fi
if [ "$PARAM2" == "" ] ; then
echo "No specified version. Starting bump $COOKBOOK (patch version) ..."
knife spork bump $PARAM1
else
echo "Starting bump $PARAM1 to $PARAM2 ..."
knife spork bump $PARAM1 manual $PARAM2
fi
knife spork upload $PARAM1
git add "cookbooks/$PARAM1/metadata.rb"
git commit -m "[Jenkins] Finished bumping $PARAM1 to $PARAM2"
git push origin master
elif [ "$OBJECT" == "role" ] ; then
knife role from file $PARAM1
echo "Uploaded role $PARAM1"
elif [ "$OBJECT" == "environment" ] ; then
knife environment from file $PARAM1
MSG="Uploaded environment $PARAM1"
elif [ "$OBJECT" == "run_list" ] ; then
if [ "$PARAM1" == "add" ] || [ "$PARAM1" == "remove" ] || [ "$PARAM1" == "set" ] ; then
echo "$PARAM1 runlist $PARAM2 $PARAM3"
knife node run_list $PARAM1 $PARAM2 "$PARAM3"
MSG="knife node run_list $PARAM1 $PARAM2 $PARAM3"
fi
else
echo "No correct command"
exit 1
fi
git checkout master
OBJECT=`git log -1 --pretty=%s | awk '{print $1}'`
PARAM1=`git log -1 --pretty=%s | awk '{print $2}'`
PARAM2=`git log -1 --pretty=%s | awk '{print $3}'`
PARAM3=`git log -1 --pretty=%s | awk '{print $4}'`
# In case, Jenkins commit merge before build
if [ "$OBJECT" == "Merge" ] ; then
OBJECT=`git log -2 --pretty=%s | tail -1 | awk '{print $1}'`
PARAM1=`git log -2 --pretty=%s | tail -1 | awk '{print $2}'`
PARAM2=`git log -2 --pretty=%s | tail -1 | awk '{print $3}'`
PARAM3=`git log -2 --pretty=%s | tail -1 | awk '{print $4}'`
fi
echo "Receiving parameter: OBJECT=$OBJECT PARAM1=$PARAM1 PARAM2=$PARAM2 PARAM3=$PARAM3"
if [ "$OBJECT" == "role" ] ; then
knife role from file $PARAM1
echo "Uploaded role $PARAM1"
elif [ "$OBJECT" == "environment" ] ; then
knife environment from file $PARAM1
MSG="Uploaded environment $PARAM1"
elif [ "$OBJECT" == "run_list" ] ; then
if [ "$PARAM1" == "add" ] || [ "$PARAM1" == "remove" ] || [ "$PARAM1" == "set" ] ; then
echo "$PARAM1 runlist $PARAM2 $PARAM3"
knife node run_list $PARAM1 $PARAM2 "$PARAM3"
MSG="knife node run_list $PARAM1 $PARAM2 $PARAM3"
fi
fi
#echo "`date +%Y%M%d%h%m`: $MSG" >> operations.log
#git add -Av
#git commit -m "$MSG"
#git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment