2

我正在尝试自动化构建过程,但我的脚本参数之一出现问题。

我存储参数,然后svn checkout %repository%在命令行上调用时替换它的值。

问题是它不能替代,我得到以下输出:

PS C:\Users\Administrator\Desktop> .\Build_Script.bat "https://mitchellt/svn/Test_Repositry/Test_Application"

C:\Users\Administrator\Desktop>rem * Need to check directory exists

C:\Users\Administrator\Desktop>rem Variables

C:\Users\Administrator\Desktop>set date=13_10_2013

C:\Users\Administrator\Desktop>set time=16-56-48

C:\Users\Administrator\Desktop>set repository = https://mitchellt/svn/Test_Repositry/Test_Application

C:\Users\Administrator\Desktop>rem Change to build directory

C:\Users\Administrator\Desktop>cd C:\Build

C:\Build>rem Make Directory for Build based on today's date

C:\Build>mkdir 13_10_2013_16-56-48

C:\Build>rem Change to new directory

C:\Build>cd 13_10_2013_16-56-48

C:\Build\13_10_2013_16-56-48>rem Create folders for the source code, built product & test results

C:\Build\13_10_2013_16-56-48>mkdir Source

C:\Build\13_10_2013_16-56-48>mkdir Product

C:\Build\13_10_2013_16-56-48>mkdir Results

C:\Build\13_10_2013_16-56-48>rem Change to source directory

C:\Build\13_10_2013_16-56-48>cd Source

C:\Build\13_10_2013_16-56-48\Source>rem Copy the source code from the repository

C:\Build\13_10_2013_16-56-48\Source>svn checkout
svn: E205001: Try 'svn help checkout' for more information
svn: E205001: Not enough arguments provided
PS C:\Users\Administrator\Desktop>

代码:

@ECHO ON
@SETLOCAL
rem * Need to check directory exists

rem Variables
set date=%DATE:/=_%
set time=%time:~0,2%-%time:~3,2%-%time:~6,2%
set repository = %1

rem Change to build directory
cd C:\Build

rem Make Directory for Build based on today's date
mkdir %date%_%time%

rem Change to new directory
cd %date%_%time%

rem Create folders for the source code, built product & test results
mkdir Source
mkdir Product
mkdir Results

rem Change to source directory
cd Source

rem Copy the source code from the repository
svn checkout %repository%
4

1 回答 1

5

问题是空格set repository = %1和批处理文件对空间敏感(仅在某些时候)。
这将创建一个名称为的变量repository<space>

只需将其更改为

set repository=%1

或更好

set "repository=%~1"

因为这也可以防止在%1

于 2013-10-13T18:57:33.877 回答