美文网首页
Gradle调用shell脚本和python脚本并传参

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

作者: 高斯巴 | 来源:发表于2019-11-07 12:15 被阅读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

    ...

    相关文章

      网友评论

          本文标题:Gradle调用shell脚本和python脚本并传参

          本文链接:https://www.haomeiwen.com/subject/gmombctx.html