Gradle调用shell脚本和python脚本并传参

2019-11-07  本文已影响0人  高斯巴

Gradle调用shell脚本和python脚本并传参

最近由于项目自动化构建的需要,研究了下gradle调用脚本并传参的用法,在此作个总结。

Pre

build.gradle中定义了$jenkinsJobName $jenkinsBuild两个Jenkins变量,意图将gradle中的这两个值传到shell/python脚本中去用

def jenkinsBuild = System.getenv("BUILD_NUMBER") ?: "0"

println "jenkinsBuild is set to $jenkinsBuild"

def jenkinsJobName = System.getenv("JOB_NAME") ?: "defaultJobName"

println "jenkinsJobName is set to $jenkinsJobName"

Gradle调用shell脚本带参数

gradle task

task upload(type: Exec) {

       executable 'sh'    args "-c","../shelldemo.sh $jenkinsJobName $jenkinsBuild"

}

shelldemo.sh脚本中

#!/usr/bin/env bash

#从build.gradle中传入的两个参数

jenkinsJobName=$1

jenkinsBuild=$2

echo "jenkinsJobName=$jenkinsJobName"

echo "jenkinsBuild=$jenkinsBuild"...

Gradle调用python脚本带参数

gradle task

task uploadpython(type: Exec) {

    workingDir './'    

    commandLine "python","pythondemo.py","$jenkinsJobName","$jenkinsBuild"

}

pythondemo.py脚本

#encoding:utf8

import sys

jenkinsJobName=sys.argv[1]

jenkinsBuild=sys.argv[2]print jenkinsJobNameprint jenkinsBuild

...

上一篇下一篇

猜你喜欢

热点阅读