I would like to split a long build command across multiple lines in my appveyor.yml file, however I cannot get it to unwrap, so the build is failing when the first FOR command gets cut off and returns an error. I am not sure how to correctly split the lines in the .yml file so that they are reassembled inside Appveyor. How can this be done?
Here is a simplified version:
build_script:
- cmd: >-
@echo off
FOR %%P IN (x86,x64) DO ( ^
FOR %%C IN (Debug,Release) DO ( ^
msbuild ^
/p:Configuration=%%C ^
/p:Platform=%%P ... ^
|| EXIT 1 ^
) ^
)
I want it to appear in AppVeyor as this:
@echo off
FOR %%P IN (x86,x64) DO ( FOR %%C IN (Debug,Release) DO ( msbuild /p:Configuration=%%C /p:Platform=%%P ... || EXIT 1 ) )
Extra spaces are unimportant, the important bit is that the line beginning with FOR until the final ) appears on the same line.
Note that in theory it would also be acceptable for Appveyor to see this:
@echo off
FOR %%P IN (x86,x64) DO ( ^
FOR %%C IN (Debug,Release) DO ( ^
msbuild ^
/p:Configuration=%%C ^
/p:Platform=%%P ... ^
|| EXIT 1 ^
) ^
)
As the Windows cmd.exe interpreter would then see the continuation markers (^) at the end of each line and treat them as one big long command, except that Appveyor does not appear to recognise the ^ marker so it sends each line to cmd.exe one at a time, instead of sending the whole multi-line block together.
This means the first option looks like the only viable solution, where the YAML is constructed such that the FOR line and everything after it is combined into a single line.
I have tried:
FOR command fails with error 255 because it is incomplete (only the FOR line is present and not the rest of the loop.)^. Appveyor only runs each line one at a time, so I get an error 255 on the first incomplete FOR command.^ as shown above. Same issue as double-spaced lines, error 255 from an incomplete FOR command.&& ^ does actually work when running separate commands (e.g. multiple msbuild statements), but this won't work with FOR loops because you can't have && without a command preceding it.Is there a trick to splitting a single cmd command over multiple lines in appveyor.yml?
How to split a command over multiple lines in appveyor.yml?
Here are some some syntax examples for batch, cmd, ps.
I hope these examples save you some time...
Syntax Examples
Batch
# please note the & at EOL in the next example
install:
# Install VULKAN_SDK
- if not exist %VULKAN_SDK% (
curl -L --silent --show-error --output Vulkan_SDK_Installer.exe https://sdk.lunarg.com/sdk/download/%VULKAN_VERSION%/windows/VulkanSDK-%VULKAN_VERSION%-Installer.exe?Human=true &
Vulkan_SDK_Installer.exe /S
)
- dir %VULKAN_SDK%
before_build:
- |-
set MINGW32_ARCH=i686-w64-mingw32
- if exist %PREFIX% set NEEDDEPENDS=rem
# Depends
- |-
%NEEDDEPENDS% mkdir %PREFIX%\include\SDL2
%NEEDDEPENDS% mkdir %PREFIX%\lib
%NEEDDEPENDS% cd %TEMP%
%NEEDDEPENDS% appveyor DownloadFile https://sourceforge.net/projects/gnuwin32/files/gettext/0.14.4/gettext-0.14.4-lib.zip
%NEEDDEPENDS% mkdir gettext-0.14.4-lib
%NEEDDEPENDS% move gettext-0.14.4-lib.zip gettext-0.14.4-lib
%NEEDDEPENDS% cd gettext-0.14.4-lib
%NEEDDEPENDS% 7z x gettext-0.14.4-lib.zip > nul
%NEEDDEPENDS% copy include\* %PREFIX%\include > nul
%NEEDDEPENDS% copy lib\* %PREFIX%\lib > nul
%NEEDDEPENDS% cd ..
deploy_script:
# if tagged commit, build/upload wheel
- IF "%APPVEYOR_REPO_TAG%"=="true" IF NOT "%TESTENV%"=="check" (
pip install twine &&
python setup.py register &&
twine upload -u %PYPI_USER% -p %PYPI_PASS% dist/*
)
CMD
before_build:
- cmd: >-
mkdir build
cd .\build
set OpenBLAS_HOME=%APPVEYOR_BUILD_FOLDER%/%MXNET_OPENBLAS_DIR%
set OpenCV_DIR=%APPVEYOR_BUILD_FOLDER%/%MXNET_OPENCV_DIR%/build
cmake .. -DOPENCV_DIR=%OpenCV_DIR% -DUSE_CUDA=0 -DUSE_CUDNN=0 -DUSE_NVRTC=0 -DUSE_OPENCV=1 -DUSE_OPENMP=1 -DUSE_BLAS=open -DUSE_DIST_KVSTORE=0 -G "Visual Studio 12 2013 Win64"
PS
install:
- ps: >-
git submodule init
git submodule update
if (!(Test-Path ${env:MXNET_OPENBLAS_FILE})) {
echo "Downloading openblas from ${env:MXNET_OPENBLAS_PKG} ..."
appveyor DownloadFile "${env:MXNET_OPENBLAS_PKG}" -FileName ${env:MXNET_OPENBLAS_FILE} -Timeout 1200000
}
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\maven" )) {
(new-object System.Net.WebClient).DownloadFile('https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip', 'C:\maven-bin.zip')
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
on_success:
- ps: |
if ($true)
{
Write-Host "Success"
}
Use double-quotes:
build_script:
- cmd: "
@echo off
FOR %%P IN (x86,x64) DO (
FOR %%C IN (Debug,Release) DO (
msbuild
/p:Configuration=%%C
/p:Platform=%%P ...
|| EXIT 1
)
)"
You can check yaml ref, and more precisely this example.
I was confronted to the same issue using appveyor (what a strange limitation !). Using double-quotes allowed me to leverage YAML subtlety to :
You can have a look where I use it and see how the build passes.
For other readers, please note, that the line will be collapsed, and as a consequence, need to be written with a special syntax to support that... you can't omit the || in the expression given by the OP for instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With