1
  • Windows Server 2012 マシンで gitlab ランナーを実行しています。
  • win-bash をインストールし、bash 実行可能ファイルの場所をシステム パスに追加しました。
  • シェルに bash を使用するようにランナーの config.toml ファイルを構成しました
  • ビルド プロセスの一部として実行する必要がある 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
4

1 に答える 1

0

インストールしたソフトウェアによって異なります。

  • Git Bash を選択して Git for Windows をインストールした場合は、Git Bash ターミナルを開き、次のようにして C: ドライブまたは D: ドライブを参照できます。

    CDC/

    cd /c/Windows/

    cd/d/

  • cygwin をインストールした場合は、次のことを行う必要があります。

    cd /cygdrive/c/

  • win-bash のマニュアルを確認してください

于 2016-12-08T12:14:18.937 に答える