jenkins插件之Ansible Plugin

本文重点说下在pipeline下的配置:

pipeline {
    agent { label 'master' }
    options {
    	timestamps()
    }

    stages {
        stage('deploy_test') {
            when {anyOf {environment name:'env',value:'test';environment name:'env',value:'dev';environment name:'env',value:'daily'}}
            steps {
                ansiColor('xterm') {
                    ansiblePlaybook colorized: true, installation: 'ansible', inventory: 'hosts', playbook: 'jdk1.8/jdk_install_test.yml',  extras: '--extra-vars env=${env}',sudoUser: null
                }

            }
            
        }
        
        stage('deploy_aliyun') {
            agent { label 'aliyun' }
            when {anyOf {environment name:'env',value:'uat';environment name:'env',value:'prod'}}
            steps {
                ansiColor('xterm') {
                    ansiblePlaybook colorized: true, installation: 'ansible', inventory: 'hosts', playbook: 'jdk1.8/jdk_install.yml',  extras: '--extra-vars env=${env}',sudoUser: null
                }

            }
            
        }

    }
    post {
    	always {
    		echo "done"
    	}
    }
}

重点是标红部分,可以是workspace的相对路径,也可以是绝对路径;

注意:上例中如果是uat或prod环境的话是通过跳板机来发布的,这里必须保证跳板机上线创建$WORKSPACE这个目录,不然会报找不到该路径的错误。

你可能感兴趣的:(持续集成,Devops,配置管理)