20220515 - 【课程贴】- 持续交付支撑工具

地址:https://pdf.ceshiren.com/dx5/jenkins

dockerfile

FROM centos

ADD entrypoint.sh /root
ADD jdk /opt/java-1.8

ENV M2_HOME=/usr/local/maven
ENV M2=$M2_HOME/bin
ENV JAVA_HOME=/opt/java-1.8
ENV PATH=$JAVA_HOME:$M2:$PATH

RUN yum install -y wget openssh-server vim git openssh-clients \
    && /usr/bin/ssh-keygen -A \
    && wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz \
    && tar xvf apache-maven-3.0.5-bin.tar.gz \
    && mv apache-maven-3.0.5  /usr/local/maven \
    && ssh-keygen -t rsa -f /root/.ssh/id_rsa -N '' \
    && cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys \
    && chmod 600 /root/.ssh/authorized_keys \
    && echo "StrictHostKeyChecking no" > /root/.ssh/config \
    && echo "UserKnownHostsFile /dev/null" >> /root/.ssh/config \
    && echo 1qaz9ol.|passwd --stdin root \
    && echo "export M2_HOME=/usr/local/maven" >> /root/.bashrc \
    && echo "export M2=$M2_HOME/bin" >> /root/.bashrc \
    && echo "export JAVA_HOME=/opt/java-1.8" >> /root/.bashrc \
    && echo "export PATH=$JAVA_HOME:$M2:$PATH" >> /root/.bashrc



ENTRYPOINT ["/bin/bash", "/root/entrypoint.sh"]

agent_docker

pipeline{
    agent any
    stages{
        stage('test1'){
            agent { label 'tech' }
            steps{
                sh """
                   echo 1111
                """
            }
        }
        stage('test2'){
            agent {
				        docker { image 'python:3.10-rc-slim' }
				    }
            steps{
                sh 'python --version'
            }
        }
    }
    post{
        always{
            sh 'echo 3333'
        }
    }
}

agent_k8s

pipeline{
    parameters {
        choice(name: 'PLATFORM_FILTER', choices: ['python352', 'python368', 'python376','all'], description: '选择测试的 python 版本')
    }
    agent{
        kubernetes{
            yaml """
            apiVersion: v1
            kind: Pod
            metadata:
              labels:
                qa: python3
            spec:
              containers:
              - name: python352
                image: python:3.5.2
                command:
                - cat
                tty: true
            """
        }
    }
    stages{
        stage('执行测试'){
            steps{
                container(params.PLATFORM_FILTER){
                  sh """
                  echo 1111111
                  """
              }
            }
        }
        
    }
    post{
        always{
            echo 'done'
        }
    }
}

agent_mutl_agents

pipeline{
    agent any
    stages{
        stage('test1'){
            agent { label 'tech' }
            steps{
                sh """
                   echo 1111
                """
            }
        }
        stage('test2'){
            agent { label 'tech_new' }
            steps{
                sh """
                   echo 2222
                """
            }
        }
    }
    post{
        always{
            sh 'echo 3333'
        }
    }
}

environment

pipeline {
    agent any
    environment { 
        name = 'frank'
    }
    stages {
        stage('setup') {
            environment { 
                address = 'beijing'
            }
            steps {
                echo 'address is ' + env.address
            }
        }
        stage('test'){
            steps {
                echo 'name is ' + env.name
            }
        }
    }
}