jenkins的pipeline

jenkins的 pipeline


node('jkt-test') {
    stage ('scp k8s-congig') {
        echo "reday for k8s-config"
        sh " echo 'test' && cd /home && touch a.txt  && ls "
                
        
    }
    

    stage ('Deploy') {
        echo "deploying......"
        sh "sleep 100"
    }
}

就是简单粗暴的开干,然后下一步就是研究该怎么写配置文件
就算你是使用helm的话 也必须要有配置文件才行。

node('jkt-test') {
    stage ('scp k8s-congig') {
        echo "reday for k8s-config"
        sh "pwd"
        sh "mkdir -p /root/.kube "
        sh """
        cat  <<EOT >>  /root/.kube/config
        中间将配置文件写好   就是连通的
        """
        sh "ls /root/.kube/"
    }
    
	stage ('Deploy') {
        echo "deploying......"
        sh "sleep 100"
    }
}
node('jkt-test') {
    stage ('scp k8s-congig') {
        echo "reday for k8s-config"
        sh " echo 'test' && cd /home && touch a.txt  && ls "
    }
    stage('YAML') {
    echo "5. Change YAML File Stage"
    def userInput = input(
        id: 'userInput',
        message: 'Choose a deploy environment',
        parameters: [
            [
                $class: 'ChoiceParameterDefinition',
                choices: "Dev\nQA\nProd",
                name: 'Env'
            ]
        ]
    )
	}
    stage ('Deploy') {
        echo "deploying......"
        sh "sleep 10"
    }
}

实际效果
在这里插入图片描述

我现在要开始整些华丽呼哨的东西了

pipeline {
  agent any

  parameters {
    choice(
      description: '你需要选择哪个模块进行构建 ?',
      name: 'modulename',
      choices: ['Module1', 'Module2', 'Module3']
    )
    
    string(
        description: '你需要在哪台机器上进行部署 ?',
        name: 'deploy_hostname', 
        defaultValue: 'host131', 
    )

    text(
        name: 'release_note', 
        defaultValue: 'Release Note 信息如下所示: \n \
Bug-Fixed: \n \
Feature-Added: ', 
        description: 'Release Note的详细信息是什么 ?'
    )

    booleanParam(
        name: 'test_skip_flag', 
        defaultValue: true, 
        description: '你需要在部署之前执行自动化测试么 ?'
    )


    password(
        name: 'deploy_password', 
        defaultValue: 'liumiaocn', 
        description: '部署机器连接时需要用到的密码信息是什么 '
    )

    file(
        name: "deploy_property_file", 
        description: "你需要输入的部署环境的设定文件是什么 ?"
    )
  }

  stages {
        stage('Build') { 
            steps { 
                echo "Build stage: 选中的构建Module为 : ${params.modulename} ..." 
            }
        }
        stage('Test'){
            steps {
                echo "Test stage: 是否执行自动化测试: ${params.test_skip_flag} ..."
            }
        }
        stage('Deploy') {
            steps {
                echo "Deploy stage: 部署机器的名称 : ${params.deploy_hostname} ..." 
                echo "Deploy stage: 部署连接的密码 : ${params.deploy_password} ..." 
                echo "Deploy stage: Release Note的信息为 : ${params.release_note} ..." 
            }
        }
    }
  }

在这里插入图片描述
出现一个问题,就是我想部署在不同的集群之中,利用congigfileprovider的插件结果是报错的。这个时候一定要用""而不是’’

properties([
  parameters([
    choice(name: 'TARGET_CLUSTER', choices: ['jkt-test','jkt-infra','jkt-elk','jkt-release'], description: 'The cluster to deploy to'),
   ])
])

def cluster = env.TARGET_CLUSTER.trim()

if(!target_cluster) {
    error "TARGET_CLUSTER must be specified"
}

node('build') {
    stage ('scp k8s-congig') {
        echo "reday for config"
        ***configFileProvider([configFile(fileId: "k8s-${cluster}-config-file", targetLocation: 'config', variable: 'kubeConfigFile')]) {***
    // some block
        }
        sh "pwd && ls"
        sh "mkdir -p /root/.kube && cp config  /root/.kube/ "
        sh "kubectl get pods"
    stage ('Clean Up') {
        echo "deploying......"
        sh "sleep 100"
    }
}
}

否则,的话报错如下
ERROR: not able to provide the file [ManagedFile: id=k8s-${cluster}-config-file, targetLocation=config, variable=kubeConfigFile], can’t be resolved by any provider - maybe it got deleted by an administrator?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值