1、新建Item,输入名称后选择Freestyle project后点击确定
2、配置项目,自定义工作目录
3、配置源码管理和要摘取的分支
4、构建触发器选择github触发
5、构建选择执行windows命令,之后点击保存
plain
#--disable-gpu,跳过语言设置,如不加此选项构建时会卡在语言设置,--path,指定构建后文件路径
echo "开始构建"
C:\CocosDashboard_1.1.0\resources\.editors\Creator\2.4.6\CocosCreator.exe --disable-gpu --path D:\game\Archery --build "platform=web-mobile;debug=false"
echo "构建完成"
echo "开始上传文件到服务器"
C:\Python38\python.exe ../../unzip.py
echo "文件上传完成"
plain
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os,json
import paramiko,zipfile,tarfile
class comupload(object):
def __init__(self, hostname, username='root', port=22):
self.private_key = paramiko.RSAKey.from_private_key_file('C:\\Users\\southpark\\.ssh\\id_rsa')
self.hostname = hostname
self.username = username
self.port = port
self.transport = paramiko.Transport((self.hostname, self.port))
self.transport.connect(username=self.username, pkey=self.private_key)
self.sftp = paramiko.SFTPClient.from_transport(self.transport)
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 允许连接不存在在know_hosts文件里的主机
self.client.connect(hostname=self.hostname, port=self.port, username=self.username, pkey=self.private_key)
def upload(self, local_path, remote_path):
# 将文件上传至服务器
self.sftp.put(local_path, remote_path)
def download(self, remotepath, localpath):
# 将文件下载到本地
self.sftp.get(remotepath, localpath)
def comand(self, com):
# 执行命令
stdin, stdout, stderr = self.client.exec_command(com)
result = stdout.read().decode()
reserr = stderr.read().decode()
return result, reserr
def exec_com(self, com):
# 执行命令,返回命令结果和状态码
self.channel = self.client.get_transport().open_session()
self.channel.exec_command(com)
stdout = self.channel.makefile().read()
stderr = self.channel.makefile_stderr().read()
exit_code = self.channel.recv_exit_status()
self.channel.close()
return stdout, stderr, exit_code
def sshclose(self):
# 关闭连接
self.sftp.close()
self.client.close()
def zipDir(dirpath,outFullName):
zip=zipfile.ZipFile(outFullName,"w",zipfile.ZIP_DEFLATED)
for path,dirnames,filenames in os.walk(dirpath):
fpath = path.replace(dirpath,'')
for filename in filenames:
print(filename,path,fpath)
zip.write(os.path.join(path,filename),os.path.join(fpath,filename))
zip.close()
def compress_file(dirpath,filename,project=None):
cur_path = os.getcwd()
os.chdir(dirpath)
tarfilename=filename+'.tar.gz'
with tarfile.open('../../../tarfile/'+tarfilename,"w") as tar:
for root,dirs,files in os.walk('.'):
for single_file in files:
filepath = os.path.join(root,single_file)
tar.add(filepath)
sshtftp=comupload('172.17.0.2')
filepath='D:\\tarfile\\{}'.format(tarfilename)
if project:
sshtftp.upload(filepath,'/root/3nm-web/site/game/{}/game/{}'.format(project,tarfilename))
sshtftp.comand("cd /root/3nm-web/site/game/{project}/game && tar xf {tarfilename} && rm -fr {tarfilename} {filename} && mv web-mobile {filename}".format(project=project,tarfilename=tarfilename,filename=filename))
else:
sshtftp.upload(filepath,'/root/3nm-web/site/game/publicgame/game/public/{}'.format(tarfilename))
sshtftp.comand("cd /root/3nm-web/site/game/publicgame/game/public && tar xf {tarfilename} && rm -fr {tarfilename} {filename} && mv web-mobile {filename}".format(tarfilename=tarfilename,filename=filename))
sshtftp.sshclose()
os.remove(filepath)
if __name__ == '__main__':
cur_path = os.getcwd()
with open("settings/builder.json") as f:
res=json.loads(f.read())
filename=res.get('title')
project=res.get('project')
if project:
compress_file('{}\\build\\'.format(cur_path),filename,project)
else:
compress_file('{}\\build\\'.format(cur_path),filename)
构建完成后上传文件到测试服务器脚本6、开启github-webhook(点击管理jenkins→配置系统→高级→勾选为github指定另外一个HooK URL)
7、启动ngrok,把forwarding地址填写到github
plain
ngrok http http://172.18.188.8:8080
注意:
如果卡在([1900] checking language setting...)检查语言设置,请检查jenkins服务登录设置,需要新建一个管理员账号,然后使用新建的管理员账号启动jenkins
参考链接:
https://ngrok.com/download #ngrok下载链接
https://github.com/FastTunnel/FastTunnel/releases # FastTunnel内网穿透