Kubernetes安装动态Jenkins

IT
IT
IT
406
文章
1
评论
2020年12月11日01:04:35 评论 4,636 2401字阅读8分0秒

构建Jenkins Slave镜像

  • Dockerfile
FROM centos:7
LABEL maintainer www.centoscn.vip

RUN yum install -y java-1.8.0-openjdk maven curl git libtool-ltdl-devel && \ 
rm -rf /var/cache/yum/* && \
mkdir -p /usr/share/jenkins

COPY slave.jar /usr/share/jenkins/slave.jar 
COPY jenkins-slave /usr/bin/jenkins-slave
COPY settings.xml /etc/maven/settings.xml
RUN chmod +x /usr/bin/jenkins-slave

ENTRYPOINT ["jenkins-slave"]
  • 下载slave.jar包方法

Kubernetes安装动态Jenkins

  • 构建镜像
[root@iZ0jl4dahgopddd1qnxqbsZ jenkins-slave]# docker build -t harbor.centoscn.cn/library/jenkins-slave-jdk:1.8 .
Sending build context to Docker daemon 1.538MB
Step 1/8 : FROM centos:7
7: Pulling from library/centos
2d473b07cdd5: Pull complete 
Digest: sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e
Status: Downloaded newer image for centos:7
---> 8652b9f0cb4c
Step 2/8 : LABEL maintainer www.centoscn.vip
---> Running in 9c0e6f61f4a7
Removing intermediate container 9c0e6f61f4a7
---> 19d2151ea64c
Step 3/8 : RUN yum install -y java-1.8.0-openjdk maven curl git libtool-ltdl-devel && yum clean all && rm -rf /var/cache/yum/* && mkdir -p /usr/share/jenkins
---> Running in 690a2258c8f6
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: centos.ipserverone.com
* extras: ossm.utm.my
* updates: centos.ipserverone.com
Step 7/8 : RUN chmod +x /usr/bin/jenkins-slave
---> Running in c4fe2332edb5
Removing intermediate container c4fe2332edb5
---> ac5e1e208738
Step 8/8 : ENTRYPOINT ["jenkins-slave"]
---> Running in 6feca320cbf0
Removing intermediate container 6feca320cbf0
---> 762e47531fcc
Successfully built 762e47531fcc
Successfully tagged harbor.centoscn.cn/library/jenkins-slave-jdk:1.8
  • 登陆harbor
[root@iZ0jl4dahgopddd1qnxqbsZ ~]# docker login https://harbor.centoscn.cn/
Username: admin
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
  • 推送到镜像仓库
[root@iZ0jl4dahgopddd1qnxqbsZ jenkins-slave]# docker push harbor.centoscn.cn/library/jenkins-slave-jdk:1.8
The push refers to repository [harbor.centoscn.cn/library/jenkins-slave-jdk]

Kubernetes安装动态Jenkins

创建流水线测试

Kubernetes安装动态Jenkins

Kubernetes安装动态Jenkins Kubernetes安装动态Jenkins

语法不会写怎么办?

Kubernetes安装动态Jenkins

  • 比如说拉取代码

Kubernetes安装动态Jenkins

  • 添加gitlab凭据

Kubernetes安装动态JenkinsKubernetes安装动态Jenkins

  • 先简单测试一下拉取代码并查看

Kubernetes安装动态Jenkins

  • 拉取代码测试

Kubernetes安装动态Jenkins

  • 简单测试是否能动态启动Jenkins-slave
podTemplate(label: 'jenkins-slave', cloud: 'kubernetes', containers: [
containerTemplate(
name: 'jnlp', 
image: "harbor.centoscn.cn/library/jenkins-slave-jdk:1.8"
),
],
) 
{
node("jenkins-slave"){
stage('拉取代码'){
git credentialsId: '79970498-96bd-405e-bdde-51ff1356f067', url: 'http://8.130.32.124/root/java-demo'
sh 'ls'
} 

}
}

Kubernetes安装动态Jenkins

  • 开始构建

Kubernetes安装动态Jenkins

  • 查看是否启用了slave-jerkins

Kubernetes安装动态Jenkins Kubernetes安装动态Jenkins

此处为隐藏的内容!
登录后方可查看!
继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
IT
  • 本文由 发表于 2020年12月11日01:04:35
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
jenkinsfile集成阿里云镜像仓库 jenkins-ci/cd

jenkinsfile集成阿里云镜像仓库

创建Jenkins认证授权 ID也配置成aliyun-registry-admin 阿里云镜像库有个问题,在设置固定密码后,使用的是本账号名字。本账号的密码和镜像的密码也就不一样了。所以要么单独创建一...

您必须才能发表评论!