- 我有一个在 Windows Server 2012 机器上运行的 gitlab 运行器。
- 我已经安装了 win-bash 并将 bash 可执行文件的位置添加到系统路径中。
- 我已将 runners config.toml 文件配置为使用 bash 作为 shell
- 我有一个 python 脚本存储在我需要作为构建过程的一部分运行的机器上。此脚本存储在 windows 机器上,位于 c:\path\to\script.py
- 我的构建脚本中的第一行打印了工作目录
pwd
并返回:/home/gitlab-runner/builds/2b321e5b/0/Firmware/PSoC5LP
我的问题是:如何访问 C:\ 驱动器?
我在 Windows 机器上运行,并从任何其他终端(cmd.exe、powershell、直接运行 bash.exe)启动 bash,从我启动 bash 的任何位置进入标准 Windows 目录结构:
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:\Users\Administrator\Desktop>bash
bash$ pwd
C:/Users/Administrator/Desktop
bash$ cd /
bash$ pwd
C:/
bash$ cd /home
bash: /home: No such file or directory
bash$ ls
$Recycle.Bin ProgramData
BOOTNXT System Volume Information
Documents and Settings Users
Miniconda2 Windows
Multi-Runner bootmgr
PerfLogs cygwin64
Program Files gitrepos
Program Files (x86) pagefile.sys
bash$
没有 /home/,看不到标准的 linux 目录结构。因此,我的构建脚本失败,因为它们无法通过绝对路径访问文件(我什至不知道它们的相对路径在跑步者 bash 上下文中会是什么样子)
这是我的构建脚本的相关部分:
#!/bin/bash
echo "build script executing"
pwd
echo "ls /"
ls /
echo "***assembling the LyteByte asm files"
# move to the LyteByteAssember directory
cd ./LyteByteAssembler/
ASSEMBLY_FILE="LyteByteAssembly.lbasm"
MERGE_FILE="merge.lbasm"
OUTPUT_FILE="../BootloaderProj.cydsn/lytebyte_prog_mem_init.c"
TEMP_DIR="./"
PREPROCESSOR_DIRECTORY="c:/gitrepos/ArcherTools/LyteByteAsembler/LyteBytePreProcessor.py"
echo $PREPROCESSOR_DIRECTORY $ASSEMBLY_FILE $MERGE_FILE $TEMP_DIR
python "$PREPROCESSOR_DIRECTORY" "$ASSEMBLY_FILE" "$MERGE_FILE" "$TEMP_DIR"
if [ $? -eq 0 ]
then
echo "Preprocessing succeeded!"
else
echo "Preprocessing failed, process cancelled"
exit 1
fi
这是跑步者的示例输出:
gitlab-ci-multi-runner 1.1.3 (a470667)
Using Shell executor...
Running on ip-172-31-7-232...
Fetching changes...
HEAD is now at d51e873 hjkj
From https://thing.githost.io/Firmware/PSoC5LP
d51e873..d77e88b CI -> origin/CI
Checking out d77e88b0 as CI...
Previous HEAD position was d51e873... hjkj
HEAD is now at d77e88b... ;jkblkn .,/p
$ bash ./build_script.sh
build script executing
/home/gitlab-runner/builds/2b321e5b/0/Firmware/PSoC5LP
ls /
bin
boot
cgroup
dev
etc
home
lib
lib64
local
lost+found
media
mnt
opt
proc
root
run
sbin
selinux
srv
sys
tmp
usr
var
***assembling the LyteByte asm files
c:/gitrepos/ArcherTools/LyteByteAsembler/LyteBytePreProcessor.py LyteByteAssembly.lbasm merge.lbasm ./
python: can't open file 'c:/gitrepos/ArcherTools/LyteByteAsembler/LyteBytePreProcessor.py': [Errno 2] No such file or directory
Preprocessing failed, process cancelled