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 @   reblue520  阅读(419)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示