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\nprod',

                     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的集成

 

posted @ 2019-03-28 17:23  reblue520  阅读(418)  评论(0编辑  收藏  举报