CocosCreator基于jenkins自动构建

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内网穿透

相关推荐
乘云数字DATABUFF2 天前
5分钟部署开源APM Databuff:OpenTelemetry全链路追踪入门实战
运维·后端
荣--4 天前
一键部署不是为了省时间 —— 它是把"买来的 PaaS"变成"自己的平台"的拐点
运维·zabbix·工程化·一键部署·平台化·边界设计
江华森4 天前
动手实战学 Docker — 从零到集群编排完全指南
运维
Avan_菜菜4 天前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
SelectDB5 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode7 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220707 天前
如何搭建本地yum源(上)
运维
大树8810 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠10 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质10 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务