定义 Pipline script
pipeline {
agent any
stages {
stage('Generate Base Dockerfile') {
steps {
script {
def dockerfileContent = """
FROM centos7.9.2009
ENV LANG en_US.UTF-8
RUN cp /usr/share/zoneinfo/Asia/Pontianak /etc/localtime \\
&& echo 'LANG="en_US.UTF-8"' > /etc/locale.conf \\
&& sed -i 's/^*/#*/g' /etc/security/limits.d/20-nproc.conf \\
&& yum install -y epel-release \\
&& yum install -y cronolog python-pip net-tools initscripts iproute vim \\
&& yum clean all \\
&& curl -sL -o /usr/bin/gosu "https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64" \\
&& chmod +x /usr/bin/gosu
"""
writeFile file: '/root/Dockerfile/Dockerfile', text: dockerfileContent
}
}
}
stage('Build Base Image') {
steps {
dir("/root/Dockerfile/"){
script {
def imageName = 'harbor.example.com/base/centos'
def imageTag = 'base'
def dockerImage = docker.build("${imageName}:${imageTag}")
dockerImage.push()
}
}
}
}
}