Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--- ref: http://jonathannicol.com/blog/2013/11/19/automated-git-deployments-from-bitbucket/ --->
- <!--- Note: Mirror the Repo one time only before using fetch and checkout --->
- <!--- Note: git clone --mirror git@bitbucket.org:<username>/<repo-name>.git --->
- <!---
- The MIT License (MIT)
- [OSI Approved License]
- The MIT License (MIT)
- Copyright (c) 2014 Steven Benjamin
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- --->
- <!--- Protect from accidential execution --->
- <cfparam name="url.key" default=""/>
- <cfif url.key NEQ "asdfgfh9gjf_hd7ss_k3rurj4fhf3dkj" OR NOT isDefined("form.payload")>
- aborted.
- <cfabort>
- </cfif>
- <!--- deserialize the posted json packet --->
- <cfset RepoStatus = DeserializeJSON(form.payload)>
- <!--- loop through the commits to get the branch --->
- <cfloop array="#variables.RepoStatus.commits#" index="commits">
- <cfif variables.commits.branch NEQ "undefined">
- <cfset branch = variables.commits.branch />
- <cfbreak>
- </cfif>
- </cfloop>
- <!--- Write the script --->
- <!--- indenting ommited to properly format text file --->
- <!--- IMPORTANT --->
- <!--- a) Change the account the Coldfusion Service Logs on with --->
- <!--- b) Log in as that account and set file permissions and SSH Keys --->
- <!--- c) Register the public key with bitbucket --->
- <cfsavecontent variable="gitInstructions">
- <cfoutput>
- ##!/bin/sh
- cd E:/REPOS.GIT/#variables.RepoStatus.repository.name#.git
- git fetch
- GIT_WORK_TREE=E:/DEV/#variables.RepoStatus.repository.name# git checkout -f #variables.branch#
- </cfoutput>
- </cfsavecontent>
- <cffile
- action = "write"
- file = "E:\REPOS.GIT\scripts\#variables.RepoStatus.repository.name#_dev.sh"
- output = "#variables.gitInstructions#"
- fixnewline = "yes">
- <!--- Execute the script --->
- <cfexecute name="C:\WINDOWS\system32\cmd.exe"
- arguments="/c E:\REPOS.GIT\Scripts\#variables.RepoStatus.repository.name#_dev.sh"
- variable="execOutput" timeout=60>
- </cfexecute>
- <!--- Diagnostics --->
- <!---
- <cfmail to="stevenbenjaminaz@gmail.com, steven@stevenbenjamin.com"
- from="server@#replaceNoCase(CGI.SERVER_NAME,'www.','')#"
- subject="Git POST Hook Report"
- type="HTML">
- <cfdump var="#variables.RepoStatus#"/>
- <cfdump var="#CGI#">
- Cfexecute Results:<br/>
- #variables.execOutput#
- </cfmail>
- --->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement