运行 使用 gitlab ci 的批处理文件并获取输出
Running the batch file using gitlab ci and getting the output
我已经用两个文件设置了我的 gitlab 项目:一个带有一个只打印 hello world
的批处理文件,另一个文件是 .gitlab-ci.yml
执行管道的文件。
批处理文件中的代码为:
ECHO OFF
ECHO 'Hello World'
PAUSE
gitlab-ci.yml文件有测试阶段:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
当我进行任何更改时,管道会启动并成功执行,但我没有从批处理文件中获得所需的输出。我在这里遗漏了什么?
管道结果如下所示:
据我所知,您只是向文件添加了 +x 权限以使其可执行,但实际上从未 运行 它。
如果你修改你的gitlab-ci.yml为:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
- ./hello-world.bat
也就是说,我不是 100% 确定这会起作用。由于这似乎是 linux 系统上的 运行,并且 .bat 脚本适用于基于 windows 的系统。
请参阅 bash 脚本以了解它们的工作原理。
因为我在 windows 上使用 gitlab-ci runner,我创建了一个 python 脚本并将其推送到自托管的 github 实例。在那个 python 脚本中,我刚刚触发了 .bat 脚本,该脚本随后运行并在项目管道中显示输出。
脚本如下所示:
import subprocess
subprocess.call([r'C:\hello.bat'])
这就是我想要的。
我已经用两个文件设置了我的 gitlab 项目:一个带有一个只打印 hello world
的批处理文件,另一个文件是 .gitlab-ci.yml
执行管道的文件。
批处理文件中的代码为:
ECHO OFF
ECHO 'Hello World'
PAUSE
gitlab-ci.yml文件有测试阶段:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
当我进行任何更改时,管道会启动并成功执行,但我没有从批处理文件中获得所需的输出。我在这里遗漏了什么?
管道结果如下所示:
据我所知,您只是向文件添加了 +x 权限以使其可执行,但实际上从未 运行 它。
如果你修改你的gitlab-ci.yml为:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
- ./hello-world.bat
也就是说,我不是 100% 确定这会起作用。由于这似乎是 linux 系统上的 运行,并且 .bat 脚本适用于基于 windows 的系统。 请参阅 bash 脚本以了解它们的工作原理。
因为我在 windows 上使用 gitlab-ci runner,我创建了一个 python 脚本并将其推送到自托管的 github 实例。在那个 python 脚本中,我刚刚触发了 .bat 脚本,该脚本随后运行并在项目管道中显示输出。
脚本如下所示:
import subprocess
subprocess.call([r'C:\hello.bat'])
这就是我想要的。