如何在以gitlab runner和bash为外壳的windows机器上访问c:


  • 我有一个gitlab运行在WindowsServer2012机器上
  • 我已经安装了win-bash,并将bash可执行文件的位置添加到系统路径中
  • 我已经将runners-config.toml文件配置为对shell使用bash
  • 我在机器上存储了一个python脚本,需要将其作为构建过程的一部分运行。此脚本存储在windows机器上,位于c:\path\to\script.py
  • 构建脚本中的第一行打印工作目录pwd并返回以下内容:/home/gitlab-runner/builds/2b321e5b/0/Firmware/PSoC5LP

我的问题是:如何访问C:\驱动器?

我在一台windows机器上运行,从任何其他终端启动bash(cmd.exe、powershell、直接运行bash.exe)会将我从任何启动bash:的地方放入标准的windows目录结构中

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:UsersAdministratorDesktop>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$

no/home/,看不到标准的linux目录结构。正因为如此,我的构建脚本失败了,因为它们无法通过绝对路径访问文件(我甚至不知道它们的相对路径在runner-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

这取决于您安装的软件:

  • 如果你已经通过选择Git Bash安装了Git for windows,那么你可以打开Git Bas终端,通过执行:浏览C:驱动器或D:驱动器

    cd/c/

    cd/c/Windows/

    cd/d/

  • 如果你已经安装了cygwin,那么你必须做:

    cd/cygdrive/c/

  • 查看您的手册以了解win-bash

相关内容

最新更新