荐 Gitlab webhooks Jenkins Android 打包: 外网Centos8主机 + FRP内网穿透 +私有内网Git源码和Maven仓库
文章来自:http://blog.csdn.net/intbird 转载请说明出处
一般情况下 公司内网 git + maven + jenkins 是同一网域公开访问的
但也有例外:比如公司没有提供***账号供外网访问, 则在家无法访问公司内网资源
如果自己在家的电脑配置够强悍,也可以远程运行服务(如jenkins)
但git中的maven仓库为公司私有网络外网无法访问,
所以有了这篇文章, 主要是内网穿透
的使用(socks代理)
注意:
公司内网穿透的风险是 会暴露公司内网服务,请严格遵守公司制度
目录
1. Centos主机防火墙设置
开放 8080 端口
firewall-cmd --add-port=8080/tcp --permanent
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld.service
2. 安装和启动Jenkins
war包方式
yum install java
curl http://*****.jenkins.war --output jenkins.war
nohup java -jar jenkins.war --httpPort=8080 >jenkins.log 2>&1 &
install方式
#安装jenkins
sudo wget -O /etc/yum.repos.d/jenkins.repo
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum upgrade
sudo yum install jenkins java-1.8.0-openjdk-devel
#启动jenkins
sudo systemctl start jenkins
3. 创建jenkins用户
浏览器打开地址
http://webhooks.ddns.net:8080/
首次进入密码
vi /var/lib/jenkins/secrets/initialAdminPassword
添加用户凭证
用于外部授权触发Jenkins任务(如gitlab等)
Jenkins user token = Jenkins → 用户 → 设置 → API Token → copy only once text
4. 安装和配置 GitLab插件
安装插件
Git + JDK + Gradle + GitLab Plugin+ GitLab Hook Plugin…
Jenkins → 系统管理 → 全局工具配置 → Git + JDK + Gradle + Maven
Jenkins → 系统管理 → 插件管理 → 可选插件 → 搜索: gitlab → 安装重启
Jenkins → 系统管理 → 系统配置 → GitLab → enable auth project → Credentials=${GitLab API token}
获取Git Token
Credentials
${GitLab API token} = GitLab → User → Access Tokens → add User Token → Copy only once text → Test Conn…
配置Android SDK
linux下载安装android sdk
wget https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip
mkdir -p /var/lib/jenkins/sdks/andorid/sdk/cmdline-tools
unzip commandlinetools-linux-6609375_latest.zip -d /var/lib/jenkins/sdks/andorid/sdk/cmdline-tools
/var/lib/jenkins/sdks/andorid/sdk/cmdline-tools/tools/bin/sdkmanager --licenses
ln -s /var/lib/jenkins/sdks/andorid/sdk ~/
sudo chmod -R 777 /var/lib/jenkins/sdks/andorid/sdk
配置jenkins环境变量
Jenkins → 系统管理 → 配置 → 全局属性 → 环境变量 → ${key,value}
如果没有sdk配置, 打包会提示: SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project’s local properties file at ‘/var/lib/jenkins/workspace/Android/local.properties’.
gradle依赖会自动安装
禁用命令: android.builder.sdkDownload=false
5. 新建任务和配置
新建任务
新建任务 → *风格的软件项目 → GitLab → 源码管理 -> repo (*.git)+ ${ ssh user & pwd}
获取ssh key
${GitLab ssh user} = GitLab → User → SSH Keys → Add an SSH key → private key text
build配置
勾选: Build when a change is pushed to GitLab: ${Webhooks url } + XX Events …
构建: 执行shell → ./gradlew :app:assembleDebug
构建: gradle build | assembleDebug
构建后通知: publish build status to gitlab
6. GitLab配置 WebHooks
Jenkins user token = Jenkins → 用户 → 设置 → API Token → copy only once text
GitLab → Pick One Project → Settings → Intergrations → ${Webhooks url}
${Webhooks url } = http://JenkinsUser:JenkinsUserToken@JenkinsIPAddress/project/projectName
Test Push ….
7. FRP访问内网maven
frps
sudo nohup ./frps -c ./frps.ini >frp_log.log 2>&1 &
[root@intbird ~]# ps -aux | grep frp
root 1335 0.0 0.0 137212 7808 ? S Aug10 0:00 sudo nohup ./frps -c ./frps.ini
root 1337 0.0 0.3 716576 24788 ? Sl Aug10 0:14 ./frps -c ./frps.ini
root 6078 0.0 0.0 12108 1096 pts/2 S+ 05:36 0:00 grep --color=auto frp
frps.ini
[common]
authentication_method = token
section = ***
bind_port = 7000
vhost_http_port = 7070
bind_udp_port = 7001
dashboard_port = 7500
dashboard_user = intbird
dashboard_pwd = ***
frpc
[1]+ Running nohup ./frpc -c ./frpc.ini > frp_log.log 2>&1 &
frpc.ini
[common]
authentication_method = token
section = xxx
server_addr = webhooks.ddns.net
server_port = 7000
admin_addr = 127.0.0.1
admin_port = 7400
admin_user = intbird
admin_pwd = xxx
[web]
type = http
local_port = 80
custom_domains = webhooks.ddns.net
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000
use_encryption = true
use_compression = true
[plugin_socks5]
type = tcp
remote_port = 8000
plugin = socks5
plugin_user = intbird
plugin_passwd = xxx
[plugin_http_proxy]
type = tcp
remote_port = 8001
plugin = http_proxy
plugin_http_user = intbird
plugin_http_passwd = xxx
frpc admin ui : 127.0.0.1:7400
Testing
- 远程7070 对应代理机器的 apach httpd 端口 80
如果能打开页面,说明服务连接正常
open http://webhooks.ddns.net:7070/
- 手机端使用代理软件,填入socks代理,访问公司内网
如果在4G网络下使用浏览器能打开公司内网git,则说明代理正常
同时服务器会log出连接日志
8. 命令行代理 和Jenkins Gradle 代理配置
命令行代理或者使用代理软件
export http_proxy=http://intbird:*****@webhooks.ddns.net:8001
socks5代理url: socks://*******#webhook
gradle代理
不要``不要``不要
勾选 Force GRADLE_USER_HOME to use workspace
不够选,则会启用 如图所示的.gradle代理配置,这样不污染git代码
systemProp.http.proxyHost=webhooks.ddns.net
systemProp.http.proxyPort=8001
systemProp.http.proxyUser=intbird
systemProp.http.proxyPassword=xxxxxx
systemProp.http.nonProxyHosts=*.aliyun.com|localhost
# systemProp.https.proxyHost=webhooks.ddns.net
# systemProp.https.proxyPort=8001
# systemProp.https.proxyUser=intbird
# systemProp.https.proxyPassword=xxxxxxx
# systemProp.https.nonProxyHosts=*.aliyun.com|localhost
# org.gradle.jvmargs=-DsocksProxyHost=webhooks.ddns.net -DsocksProxyPort=8000
Java代理
org.gradle.jvmargs=-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080
9. 打包和通知
gitlab webhooks
jenkins jobs
gitlab 通知
gitlab自动发送打包结果邮件
end…
文章来自:http://blog.csdn.net/intbird 转载请说明出处
本文地址:https://blog.csdn.net/intbird/article/details/107933129