svn钩子脚本:
post-commit.bat
@echo off
SET REPOS=%1
SET REV=%2
SET DIR=%REPOS%/hooks
SET PATH=%PATH%;
SET WORKING=D:/jenkins
"C:\Program Files\TortoiseSVN\bin\svn.exe" update %WORKING% --username "test" --password "test123"
python "D:\scripts\sys1.py" %REV%
sys1.py
#!/usr/bin/env python
#_*_coding:utf-8 _*_
import urllib,urllib2
import json
import sys
import simplejson
import subprocess
def gettoken(corpid,corpsecret):
gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret
print gettoken_url
try:
token_file = urllib2.urlopen(gettoken_url)
except urllib2.HTTPError as e:
print e.code
print e.read().decode("utf8")
sys.exit()
token_data = token_file.read().decode('utf-8')
token_json = json.loads(token_data)
token_json.keys()
token = token_json['access_token']
return token
def senddata(access_token,user):
info=sys.argv[1]
send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token
#p=subprocess.Popen("/root/wechat/check_app.sh",shell=True,stdout=subprocess.PIPE)
#content1 = p.stdout.read()
send_values = {
"touser":user,
"toparty":"1",
"msgtype":"text",
"agentid":1,
# "text":{"content":"测试消息,请无视"},
"text":{"content":"告警信息" + '\n' + "svn有更新,版本号为:" + info},
"safe":"0"}
# send_values["text"]["content"]="欢迎"
# send_data = json.dumps(send_values, ensure_ascii=False)
send_data = simplejson.dumps(send_values, ensure_ascii=True).encode('utf-8')
send_request = urllib2.Request(send_url, send_data)
response = json.loads(urllib2.urlopen(send_request).read())
print str(response)
if __name__ == '__main__':
user='gui'
#content='欢迎光临'
corpid ='wx86…………'
corpsecret = 'X_gA-r………………………………'
accesstoken = gettoken(corpid,corpsecret)
senddata(accesstoken,user)
里面通过info 变量传入svn版本号,微信告警通知。