如何将GITHUB中的文件传递给python脚本并使用jenkins自动化?

问题描述 投票:0回答:1

我有一个自动化websphere角色映射的python脚本,截至目前该文件已被设置为环境变量。但现在我需要在GITHUB中拥有该文件并通过jenkins工作传递它如何实现这一目标?将尝试详细说明下面是我的代码示例

print("*******************")
import sys
import java.lang.System as system
import os
doUpdateAccessIDs = 0
aclfilename=os.environ['APPLICATIONSECURITYINPUTFILE']
if aclfilename == "":
    raise Exception("YOU MUST PROVIDE THE FULL FILEPATH TO THE ACL FILE through the environment variable APPLICATIONSECURITYINPUTFILE")
    sys.exit

APPLICATIONSECURITYINPUTFILE是一个txt文件,设置为shell中的环境变量。现在它必须从GITHUB repo读取,而不是从本地读取。我怎么设置这个。

jenkins github automation jenkins-pipeline
1个回答
0
投票

您需要知道git存储库中python文件的位置是什么,并使用pass传递给python,例如$ WORKSPACE / data / myfile.txt(传递给文件)

--file_path $ WORKSPACE / data / myfile.txt

我调整我的代码以帮助:

import argparse

def print_options(options):
    print "file_path: %s" % options.file_path


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("-f", "--file_path", help="APPLICATION SECURITY INPUT FILE", default="/opt/myfile")


    options=parser.parse_args()
    print_options(options)
    return vars(options)


def main():
    print ' *** start jenkins job script ***'
    option = get_args()


if __name__ == "__main__":
    main()
© www.soinside.com 2019 - 2024. All rights reserved.