[英]In Github, can I run a python script from a different repo than where it's stored?
Let's say I have aa repo that has a python script stored in it, then another repo where I want to run that script, such as below within repo1. 假设我有一个存储了python脚本的存储库,然后是另一个我想运行该脚本的存储库,例如repo1中的以下代码。
sh "python repo2/src/python.py --arg value --arg2 value2"
I'm sorry. 对不起。 I know this seems like a simple question, but I either don't know how to phrase my question or else it's just not possible. 我知道这似乎是一个简单的问题,但是我要么不知道如何表达我的问题,要么就不可能。
Thank you. 谢谢。
More info: The script is part of a repo and this is where it needs to live, especially to stay modular. 更多信息:脚本是回购的一部分,这是脚本存在的地方,尤其是保持模块化的地方。 The other repo is a for a pipeline and it has a groovy Jenkinsfile. 另一个存储库是用于管道的,它具有一个普通的Jenkinsfile。 This is where I want to pull that script and run in within the Jenkinsfile 这是我要提取该脚本并在Jenkinsfile中运行的地方
You can write a bash script that moves into the desired directory for you and executes the file from there. 您可以编写一个bash脚本,该脚本将移至所需的目录并从该目录执行文件。 Let's say you want to execute program2.py in another directory from where you actually want to call it, then you could write a simple bash script to do this for you: 假设您要在另一个实际要调用它的目录中执行program2.py,那么您可以编写一个简单的bash脚本来为您执行此操作:
#!/bin/sh
cd path/to/dir/where/program2.py/is/stored
python program2.py --arg value
Save this bash script with a .sh file ending. 保存此bash脚本,并以.sh文件结尾。 Then just make it executable with chmod +x
and make sure it's in the same directory as the directory where you want to execute it, of course, and you should be good to go! 然后,只需使用chmod +x
使它可执行,并确保它与您要执行该目录的目录位于同一目录中,那么您应该一切顺利!
假设您有一个正在读取文本文件的python脚本,您可以按照以下代码执行代码,它将起作用
python /dir/to/your/file.py /dir/to/another_file.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.