zoukankan      html  css  js  c++  java
  • 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的集成

  • 相关阅读:
    https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic net::ERR_CONNECTION_TIMED_OUT问题解决
    nginx 下使用 bootstrap 字体的问题
    php中函数preg_match或preg_match_all 第三个参数$match的解释
    thinkphp中 volist循环的 mod取值的问题
    mysql中sql注入的随笔
    修改mysql的字符集和默认存储引擎
    使用Marsedit在博客园写作
    Server Tomcat v7.0 Server at localhost failed to start.临时解决办法
    【转】Linux Mint 17.2 gedit中文乱码
    HashMap和HashSet
  • 原文地址:https://www.cnblogs.com/reblue520/p/10616412.html
Copyright © 2011-2022 走看看