【发布时间】:2019-05-24 11:12:40
【问题描述】:
所以我是 Jenkins/Git 的新手。我的问题可能很基本,但请花点时间回答。
所以我正在尝试一个简单的事情。我有一个在 git 上推送的简单 Python 脚本。就是这样:
def about_me(your_name):
print("The wise {} loves Python.".format(your_name))
def HW():
print("Hello World!")
def Both():
HW()
about_me("Ab")
Both()
F = open(r"C:\Users\AMRABET\Documents\VSC\HW\a.txt", "a")
F.write("ok\n")
没什么大不了的。只是一个控制台/文件打印。 我把它推到了我的 git 的 master 分支上。
接下来,我尝试通过 Jenkins 执行它。在互联网上阅读了多个主题后,我了解到实际上 Jenkins 并没有运行代码。它只构建它。
所以我做了构建它。我在 Jenkins 和 Git 之间配置了一个连接,我成功了。这是构建的输出:
Running as SYSTEM
Building in workspace C:\Program Files (x86)\Jenkins\workspace\GitJob
using credential 1f413199-4637-40b4-96b9-a06e1d5aab4c
> C:\Program Files\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> C:\Program Files\Git\bin\git.exe config remote.origin.url https://github.com/MbtAbd/HelloWorld # timeout=10
Fetching upstream changes from https://github.com/MbtAbd/HelloWorld
> C:\Program Files\Git\bin\git.exe --version # timeout=10
using GIT_ASKPASS to set credentials
> C:\Program Files\Git\bin\git.exe fetch --tags --force --progress https://github.com/MbtAbd/HelloWorld +refs/heads/*:refs/remotes/origin/*
> C:\Program Files\Git\bin\git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> C:\Program Files\Git\bin\git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision 34500678072eb8536821606367d6ecf329d344d9 (refs/remotes/origin/master)
> C:\Program Files\Git\bin\git.exe config core.sparsecheckout # timeout=10
> C:\Program Files\Git\bin\git.exe checkout -f 34500678072eb8536821606367d6ecf329d344d9
Commit message: "Added the file writing stuff"
> C:\Program Files\Git\bin\git.exe rev-list --no-walk 34500678072eb8536821606367d6ecf329d344d9 # timeout=10
Finished: SUCCESS
谁能告诉我如何通过 Jenkins 运行 build 的结果? StackOverflow 上的所有其他线程都建议执行 shell 操作 (sh 'python script.py'),但在我的情况下,我并没有真正的 PY 文件。
感谢任何帮助。感谢社区!
【问题讨论】:
-
为什么没有
.py文件?它应该从 git 存储库中检出。 -
嗯,首先,你的 python 脚本并不一定要“构建”——而且看起来构建脚本所做的不仅仅是检查提交。此外,您的意思是“实际上没有 py 文件”- 这正是您放入 git 存储库的内容,不是吗?另外,你为什么要从 Jenkins 开始运行这个脚本?
-
是的。我的意思是我不想编译我机器上的 py 脚本。我希望它执行他在 git 上找到的脚本。这就是我的意思
-
在 Jenkins 上做 sh 'python script.py' 执行机器上的 script.py 文件,不是吗?
-
Jenkins 似乎是一个错误的工具,但更重要的是,
sh 'python script.py'在构建机器上执行脚本,即。刚刚检查了你的 git commit 的那个。它确实应该有可用的脚本文件。