• Gitlab_ansible_jenkins三剑客⑤jenkins Pipeline-job的使用


    Pipeline-job的使用

    创建Pipeline任务

    找到root用户的id

    编写pipeline脚本

    #!groovy

    pipeline{

           agent {node {label 'master'}}

           environment {

                  PATH="/bin/:sbin:usr/bin:usr/sbin:/usr/local/bin"

           }

           parameters {

                  choice(

                         choices: 'dev prod',

                         description: 'choose deploy environment',

                         name: 'deploy_env'

                         )

                  string (name: 'version', defaultValue: '1.0.0', description: 'build version')

           }

           stages {

                  stage("checkout test repo") {

                         steps {

                               sh 'git config --global http.sslVerify false'

                               dir ("${env.WORKSPACE}") {

                                      git branch: 'master', credentialsId: "6bdd72fd-dcc1-4977-9978-4982aae37dc9", url: 'https://root@gitlab.example.com/root/test-repo.git'

                               }

                         }

                  }

                  stage("Print env variable") {

                         steps {

                               dir ("${env.WORKSPACE}") {

                                      sh """

                                      echo "[INFO] print env variable"

                                      echo "current deployment environment is $deploy_env" >> test.properties

                                      echo "the build is $version" >> test.properties

                                      echo "[INFO] Done..."

                                      """

                               }

                         }

                  }

                  stage("check test properties") {

                         steps{

                               dir ("${env.WORKSPACE}") {

                                      sh """

                                      echo "[INFO] check test properties"

                                      if [ -s test.properties ]

                                      then

                                             cat test.properties

                                             echo "[INFO] done..."

                                      else

                                             echo "test.properties is empty"

                                      fi

                                      """

                                      echo "[INFO] build finished..."

                               }

                         }

                  }

           }

    }

    编译结果:

    Jenkins与基础应用集成

    打开shell模块编辑

    编写测试脚本

    #!/bin/sh

    user=`whoami`

    if [ $user == 'deploy' ]

    then

           echo "hello, my name is $user"

    else

           echo "sorry, i am not $user"

    fi

    ip addr

    cat /etc/system-release

    free -m

    df -h

    py_cmd=`which python`

    $py_cmd --version

    带参数的界面

    添加参数选项

    脚本

    #!/bin/sh

    echo "current deploy environment is $deploy_env"

    echo "the build is $version"

    echo "the password is $pass"

    if $bool

    then

           echo "request is appoved"

    else

           echo "request is rejected"

    fi

    编译结果

    Jenkins和git的集成

  • 相关阅读:
    [LeetCode每日1题][简单] 169. 多数元素
    [LeetCode每日1题][简单] 1013. 将数组分成和相等的三个部分
    [LeetCode每日1题][中等] 322. 零钱兑换
    [LeetCode每日1题][中等] 面试题59
    软工实践个人总结
    2019 SDN大作业
    2019 SDN上机第7次作业
    第01组 Beta版本演示
    如果有一天我变得很有钱组——alpha冲刺day7
    如果有一天我变得很有钱组——alpha冲刺day6
  • 原文地址:https://www.cnblogs.com/reblue520/p/10616412.html
Copyright © 2020-2023  润新知