WSO2使用Jenkins进行CI/CD
WSO2安装使用的全过程详解: https://blog.csdn.net/weixin_43916074/article/details/127987099.
1. Tool Install
1.0 Port
- 详细资料请看上面的链接
wos2 port:9443
gitlab port:38080
jenkins port:8888
1.1 wso2 Install
- 拉取镜像/版本
docker pull wso2/wso2am
docker pull wso2/wso2am:4.0.0 => 可以指定版本
- 使用root权限创建容器(里面还有jenkins port的映射8888)
Docker run reference: https://docs.docker.com/engine/reference/run/.
docker run --privileged=true -u=root -d -p 9443:9443 -p 9763:9763 -p 9999:9999 -p 11111:11111 -p 8280:8280 -p 8243:8243 -p 5672:5672 -p 9711:9711 -p 9611:9611 -p 9099:9099 -p 8888:8080 --name mywso2 wso2/wso2am
- 访问UI
https://xxx.xxx.xxx.xxx:9443
1.2 Tool Install
1.2.1 Install git/vim
- 升级
apt-get -y update
- install git/vim
apt-get install -y git
apt-get install -y vim
1.2.2 Install jdk
- wos2 dockerfile已经装了jdk
- install 1.8 jdk(注意安装目录)
apt-get install -y openjdk-8-jdk
- 好像是修改/etc/profile,就可以覆盖掉dockerfile的配置
自己想用哪个配哪个
1.2.3 Install jenkins
- install jenkins
最新版本Jenkins需要java11,如果你的环境是java8 ,可以选择war包安装
apt-get install jenkins
- 要升级(容器使用root权限创建的,不需要sudo)
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | tee /etc/apt/sources.list.d/jenkins.list > /dev/null
apt-get update
apt-get install jenkins
- 安装systemctl
sudo apt-get install -y systemctl
systemctl start jenkins
- 管理员密码
cat /var/lib/jenkins/secrets/initialAdminPassword
- 修改配置后执行
systemctl daemon-reload
- 重启Jenkins
systemctl stop jenkins
systemctl restart jenkins
- 删除Jenkins
apt-get remove jenkins
apt-get remove --auto-remove jenkins
apt-get purge jenkins
apt-get purge --auto-remove jenkins
1.3 Jenkins Install
- 下载jenkins war
Downloading Jenkins: https://www.jenkins.io/download/.
- 复制到容器
mkdir software
容器中创建目录
docker cp jenkins.war mywso2:/home/wso2carbon/software
- 顺便把apictl也装了
docker cp apictl-4.0.1-linux-x64.tar.gz mywso2:/home/wso2carbon/software
tar -zxvf apictl-4.0.1-linux-x64.tar.gz
ln -s /home/wso2carbon/software/apictl/apictl /usr/bin/apictl
- 编辑启动文件 =>看dockerfile就懂了
vim jenkins_stare.sh
export JAVA_HOME=/opt/java/openjdk
nohup $JAVA_HOME/bin/java -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -jar /home/wso2carbon/software/jenkins.war 2>&1 &
- 密码
cat /root/.jenkins/secrets/initialAdminPassword
- 登陆(前面创建容器的时候做了映射)
http://xxx.xx.xx.xx:8888
- 再写一个关闭的文件
vim jenkins_stop.sh
#!/bin/bash
PID=$(ps -ef | grep jenkins.war | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo Application is already stopped
else
echo kill $PID
kill $PID
fi
2. Jenkins CI/CD
2.1 Setting up the environment
2.1.1 Jenkins config
- 需要的环境
- Install jq
apt-get install -y jq
- 安装插件
Generic Webhook Trigger
- config apictl
2.1.2 Setup repository
- 容器中创建目录
mkdir repository
git init
- 连接仓库
git config --global user.name ‘xxxx’
git config --global user.email ‘xxxx’
git clone http://10.136.217.213:38080/nan/source.git
git clone http://10.136.217.213:38080/nan/deployment.git
- set repository webhook
apt-get install jq
- gitlab 先开启可以访问自己
gitlab 10.6 版本以后为了安全,不允许向本地网络发送webhook请求,所以先勾选- create jenkins pipeline
- config
选择前面安装的插件
设定token,给gitlab触发的方法
http://xxx.xxx.xx.xx:8888/generic-webhook-trigger/invoke=admin
配置仓库的地址和账密
- 也可以提前配置
- gitlab repository cinfig webhook
http://xxx.xxx.xx.xx:8888/generic-webhook-trigger/invoke=admin
这个在jenkins里面配置了
- run jenkins pipeline
注意是main,不是master
- 继续添加环境变数
APIM_DEV_HOST
2.2 Jenkins Pipeline Script
2.2.1 Source Pipeline Script
xxxx
- 下载脚本,修改参数,满足自己的条件
pipeline {
agent {
node {
label 'main'
}
}
options {
buildDiscarder logRotator(
daysToKeepStr: '16',
numToKeepStr: '10'
)
}
stages {
stage('Preparation') {
steps{
git branch: "main",
url: 'http://xxxx.xxx.xxx:38080/nan/source.git'
}
}
stage('Setup Environment for APICTL') {
steps {
sh '''#!/bin/bash
#rm /root/.jenkins/workspace/gitconfig
#touch /root/.jenkins/workspace/gitconfig
apictl set --vcs-config-path /root/.jenkins/workspace/gitconfig
envs=$(apictl get envs --format "{
{.Name}}")
if [ -z "$envs" ];
then
echo "No environment configured. Setting dev environment.."
apictl add env dev --apim https://${
APIM_DEV_HOST}:9443
else
echo "Environments :"$envs
if [[ $envs != *"dev"* ]]; then
echo "Dev environment is not configured. Setting dev environment.."
apictl add env dev --apim https://${
APIM_DEV_HOST}:9443
fi
fi
'''
}
}
stage('Build api bundles and upload') {
steps {
sh '''#!/bin/bash
apictl login dev -u admin -p admin -k
apis=$(apictl vcs status -e dev --format="{
{ jsonPretty . }}" | jq -r '.API | .[] | .NickName')
mkdir -p upload
if [ -z "$apis" ];
then
echo "======== No API Changes detected ==========";
else
echo "Updated APIs :"$apis
apiArray=($apis)
for i in "${apiArray[@]}"
do
echo "$i"
apictl bundle -s $i -d upload
# get the artifact deploy version from the meta.yaml
versionFull=$(cat $i/meta.yaml)
versionId=(${
versionFull//: / })
version=${
versionId[1]}
for file in upload/*; do
echo "Uploading "$file
curl -u ${ARTIFACTORY_USER}:${ARTIFACTORY_PWD} -X PUT https://${ARTIFACTORY_HOST}/artifactory/${ARTIFACTORY_REPO}/$i/$version/ -T $file
done
rm -rf upload
done
fi
'''
}
}
stage('Update local repo') {
steps {
sh '''#!/bin/bash
idFull=$(cat vcs.yaml)
arrId=(${idFull//: / })
repoId=${arrId[1]}
head=$(git rev-parse HEAD)
rm /root/.jenkins/workspace/gitconfig
echo "
repos:
$repoId:
environments:
dev:
lastAttemptedRev: $head" >> /root/.jenkins/workspace/gitconfig
'''
}
}
}
}
2.2.2 Deployment Pipeline Script
xxxx
3. Error
3.1 OIDCSessionIFrameServlet Error
- 报警如下
ERROR - OIDCSessionIFrameServlet Error while retrieving OAuth application information for the provided client id : null, Cannot find an application associated with the given consumer key : null
- 日志路径
cd /home/wos2carbon/wso2am-4.0.0/repository/logs
- UI界面一直打不开,自己莫名其妙的又好了,可以打开了。。。。。。
4. Awakening
在一秒钟内看到本质的人和花半辈子也看不清一件事本质的人,自然是不一样的命运。
转载:https://blog.csdn.net/weixin_43916074/article/details/128246800
查看评论