pipeline样例及应用

1. pipeline简单框架

pipeline {
    agent any
    
    stages {
        stage('Chekout') {
            steps {
                echo 'check out source code'
            }
        }
        stage('Build') {
            steps {
                echo 'mvn clean package'
            }
        }
        stage('scan') {
            steps {
                echo 'scan source code to sonar'
            }
        }
        stage('Deploy') {
            steps {
                echo 'deploy project via ansible'
            }
        }
    }
}

2. pipeline应用

ln -s /usr/local/maven/bin/mvn /usr/bin
ln -s /usr/local/java/bin/java /usr/bin
pipeline {
    agent {label 'master'}
    stages {
        stage('Checkout') {
            steps {
                echo "checkout source code"
                git 'https://github.com/gjjcommon/game-of-life.git'
            }
        }
        stage('Build') {
            steps {
                echo "Build source code"
                sh 'mvn clean package'
            }
        }
        stage('Scan') {
            steps {
                echo "use sonarqube and scanner to scan code"
            }
        }
        stage('Confirm') {
            steps {
                input "Plese confirm deployment:"
            }
        }
        stage('Deploy') {
            steps {
                echo "deploy war file"
                sh '/tmp/deploy.sh'
            }
        }
    }
}

在这里插入图片描述

pipeline {
    agent {label 'master'}
    
    stages {
        stage('Checkout source code') {
            steps {
                echo "pull source code from git repository"
                git credentialsId: '1506164a-3942-48c6-8f03-5f9f5715b3e5', url: '[email protected]:f4/game-of-life.git'
            }
        }
        stage('Build') {
            steps {
                echo "Build project"
                sh 'mvn clean package'
            }
        }
        stage('Confirm') {
            steps {
                input "Confirm whether deploy project or not?"
            }
        }
        stage('Deploy') {
            steps {
                echo "Deploy web project"
                sh '/tmp/hello.sh'
            }
        }
        stage('Sonar') {
            steps {
                echo "Check source code quality"
                echo  "scanner ...."
            }
        }
        stage('Email') {
            steps {
                echo "Sending results of project"
                echo "mail to requestor"
            }
        }
    }
}
发布了67 篇原创文章 · 获赞 56 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43557605/article/details/103068022