jenkins自动化部署

##  安装Jenkins插件安装:git

pipeline {
  agent {
    kubernetes {
      inheritFrom "jenkins-slave"
      yaml '''
apiVersion: v1
kind: Pod
metadata:
  name: jenkins-slave
spec:
  containers:
  - name: jnlp
    image: "registry.cn-hangzhou.aliyuncs.com/xinhuixu/public:jenkins-slave-jdk1.8"
'''
    }
  }
//  ## 设置日志时间输出(可用于阶段级别)
  options { timestamps() }
  //定义变量
  environment { 
      NAME = "xhx"
  }
    parameters {
      choice choices: ['default', 'dev', 'test', 'prot'], description: '请选择命名空间', name: 'Namespase'
      extendedChoice description: '兴趣爱好', multiSelectDelimiter: ',', name: 'Like', quoteValue: true, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value: '美女,跑车,大别墅', visibleItemCount: 5
    }  
//    triggers { cron('*/1 * * * *')}
    stages {
    stage('Main'){
                input {
                message "是否继续?"
                ok "Yes, we should."
                submitter "xhx"
                parameters {
                    string(name: 'HELLO', defaultValue: 'k8s', description: '请输入问好语句?')
                }
            }
      steps {
        sh "echo ${NAME};echo ${Namespase},echo ${Like};echo ${HELLO}"
        withCredentials([usernamePassword(credentialsId: '2134e4a9-633d-4a53-84de-dedbf33fa619', passwordVariable: 'password', usernameVariable: 'username')]) {
        // some block
        echo "账号密码,$username,$password"
        }
        script {
            
            if (HELLO == '1') {
                echo "执行1的操作..."
            }else {
                echo "执行2其它操作...."
            }
            def browsers = ['chrome', 'firefox']
            for ( i in browsers ) {
                echo "$i"
                if (i == 'chrome') {
                    echo "chrome执行1的操作..."
                }else {
                    echo "执行2其它操作...."
                }
            }

        }
      }
    }

  }
    post { 
        always { 
            echo 'send dingding ntice'
        }
        success {
            echo 'job success send dingding '
        }
        failure {
            echo 'job failure ! send dingding'
        }
    }
}


你可能感兴趣的:(jenkins,自动化,运维)