How to pass Packer.io ISO_URL as a command line parameter - packer

I would like to pass ISO_URL as a command line parameter. I tried to follow an example at https://www.packer.io/docs/templates/user-variables.html
Where my variable section looks like
"variables": {
"build_version": "1.0.0",
"iso_checksum_type":"md5",
"iso_checksum":"453312bf56fc45669fec5ebc0f025ac7",
"iso_url":"c:\fake.iso"
}
the variable references
...
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type":"{{user `iso_checksum_type`}}",
"iso_url": "{{user `iso_url`}}",
...
and the build command is
packer build -var 'iso_url=c:\debian.iso' packerio.json
However, the iso_url is not overwritten and packer is trying to download the fake.iso
Why?
The exact result is
virtualbox-iso output will be in this color.
==> virtualbox-iso: Downloading or copying Guest additions
virtualbox-iso: Downloading or copying: file:///C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
==> virtualbox-iso: Downloading or copying ISO
virtualbox-iso: Downloading or copying: file:///c:/fake.iso
virtualbox-iso: Error downloading: GetFileAttributesEx c:/fake.iso: The system cannot find the file specified.
==> virtualbox-iso: ISO download failed.
Build 'virtualbox-iso' errored: ISO download failed.
==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: ISO download failed.
==> Builds finished but no artifacts were created.

The solution is to replace the single quote with double or leave the quotes out.
packer build -var "iso_url=c:\debian.iso" packerio.json
or
packer build -var iso_url=c:\debian.iso packerio.json
Also, relative path works too
packer build -var iso_url=\subfolder_name\debian.iso packerio.json
Thank you #RickardvonEssen for pointing me in the right direction.

Related

Getting logs/more information during start-build command execution

Jenkins pipeline is building Docker images. OpenShift plugin(s) are used for the same.
An example command:
openshift.selector(BUILD_CONFIG_NAME, "${appBcName}").startBuild("--from-dir=${artifactPath}", '--wait','--follow')
While this works smoothly most of the time, whenever this command fails due to some underlying platform issues, almost no information is seen in the Jenkins build job console:
[Pipeline] }
[start-build:buildconfig/amld5-car-reporting-spacetime-ubi-openshift-java-runtimejd] ............................................................
[start-build:buildconfig/amld5-car-reporting-spacetime-ubi-openshift-java-runtimejd] Uploading finished
[start-build:buildconfig/amld5-car-reporting-spacetime-ubi-openshift-java-runtimejd] Error from server (BadRequest): unable to wait for build amld5-car-reporting-spacetime-ubi-openshift-java-runtimejd-857 to run: timed out waiting for the condition
[Pipeline] }
ERROR: Error running start-build on at least one item: [buildconfig/amld5-car-reporting-spacetime-ubi-openshift-java-runtimejd];
{err=, verb=start-build, cmd=oc --server=https://api.scp-west-zone02-z01.net:6443 --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt --namespace=sb-1166-amld5-car-service-se --token=XXXXX start-build buildconfig/amld5-car-reporting-spacetime-ubi-openshift-java-runtimejd --from-dir=./build/libs --wait --follow -o=name , out=Uploading directory "build/libs" as binary input for the build ...
............................................................
Uploading finished
Error from server (BadRequest): unable to wait for build amld5-car-reporting-spacetime-ubi-openshift-java-runtimejd-857 to run: timed out waiting for the condition
, status=1}
[Pipeline] // catchError
I need more verbosity, detailed error information. I checked the start-build command reference, and I thought --build-loglevel [0-5] might help here. When I used it, I got a warning that since I am using source type as 'Binary' in the BuildConfig, logging isn't supported(seriously???)
NOTE: the selector returned when -F/--follow is supplied to startBuild() will be inoperative for the various selector operations.
Consider removing those options from startBuild and using the logs() command to follow the build output.
[start-build:buildconfig/casc-docs-spacetime-ubi-openshift-java-runtimeadoptopenjdk] WARNING: Specifying --build-loglevel with binary builds is not supported.
[start-build:buildconfig/casc-docs-spacetime-ubi-openshift-java-runtimeadoptopenjdk] WARNING: Specifying environment variables with binary builds is not supported.
[start-build:buildconfig/casc-docs-spacetime-ubi-openshift-java-runtimeadoptopenjdk] Uploading directory "build/libs" as binary input for the build ...
[start-build:buildconfig/casc-docs-spacetime-ubi-openshift-java-runtimeadoptopenjdk] ..
How do I get more logs, info. while executing the start-build command?
I was facing the same problem, I just used something like:
def build = openshift.selector(BUILD_CONFIG_NAME, "${appBcName}").startBuild("--from-dir=${artifactPath}", '--wait','--follow')
build.logs('-f')
And so far it seems to work, I got the logs from my openshift build in my Jenkins pipeline. Now I'll try to get the logs only if build does not Complete, to reduce the overall logs.
(for future searchers like me ^^)

Pipeline fails when running Packer fix

I'm trying to run Packer (1.7) in an Azure DevOps pipeline.
The pkr.hcl files passes validation on my PC running Packer 1.7.3. The pipeline runs Packer 1.7.2.
The YAML task in the pipeline reads like this:
- task: PackerBuild#1
inputs:
templateType: 'custom'
customTemplateLocation: 'ComboBoxes.pkr.hcl'
imageUri: 'ssi-dev-combobox'
imageId: <full resource ID>
When run in the pipeline it reads:
Current installed packer version is 1.7.2.
Running packer fix command
/usr/local/bin/packer fix -validate=false /home/vsts/work/1/s/ComboBoxes.pkr.hcl
Error parsing template: invalid character '#' looking for beginning of value
##[error]Packer fix command failed with error : ''. This could happen if task does not support packer version.
The # is the first character in the .pkr.hcl file. And changing the beginning of the file will change what character shows up as invalid.
Why is it trying to run "packer fix" instead of "packer build"?
So it turns out that the Packer task in Azure Pipelines doesn't work with current versions of Packer.
Run Packer as part of a script task instead.
- task: PowerShell#2
displayName: 'Packer build'
inputs:
targetType: 'inline'
script: 'packer build $(build.artifactstagingdirectory)/ComboBoxes.pkr.hcl'

SSIS Project Fails To Build On Self Hosted Agent

I've seen other issues documented regarding SSIS project build failures but nothing that fits my scenario.
I am attempting to build an SSIS project (.dtproj) on a self hosted agent.
The project builds fine in Visual Studio 2019 and also on Azure Pipelines, but when I attempt to build it with the self hosted agent (via Command Line Task in a Build Pipeline in Azure DevOps) I get the following errors:
[debug]Evaluating condition for step: 'Build SSIS Packages'
[debug]Evaluating: succeeded()
[debug]Evaluating succeeded:
[debug]=> True
[debug]Result: True Starting: Build SSIS Packages
======================================================================== Task : Command line Description : Run a command line script
using Bash on Linux and macOS and cmd.exe on Windows Version: 2.151.2 Author: Microsoft Corporation
=========================================================================
[debug]VstsTaskSdk 0.9.0 commit 6c48b16164b9a1c9548776ad2062dad5cd543352
[debug]Entering C:\My Project\agent_work_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.151.2\cmdline.ps1.
[debug]Loading resource strings from: C:\My Project\agent_work_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.151.2\task.json
[debug]Loaded 6 strings.
[debug]SYSTEM_CULTURE: 'en-US'
[debug]Loading resource strings from: C:\My Project\agent_work_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.151.2\Strings\resources.resjson\en-US\resources.resjson
[debug]Loaded 6 strings.
[debug]INPUT_FAILONSTDERR: 'false'
[debug] Converted to bool: False
[debug]INPUT_SCRIPT: 'echo Building SsisProject...
[debug]
[debug]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.com" C:\My
Project\agent_work\1\s\MySolution.sln /build Development /project
C:\My
Project\agent_work\1\s\ETL\Integration\MySsisProject\MySsisProject.dtproj'
[debug]INPUT_WORKINGDIRECTORY: 'C:\My Project\agent_work\1\s'
[debug]Asserting container path exists: 'C:\My Project\agent_work\1\s' Generating script.
[debug]AGENT_VERSION: '2.155.1'
[debug]AGENT_TEMPDIRECTORY: 'C:\My Project\agent_work_temp'
[debug]Asserting container path exists: 'C:\My Project\agent_work_temp'
[debug]Asserting leaf path exists: 'C:\WINDOWS\system32\cmd.exe'
========================== Starting Command Output ========================
[debug]Entering Invoke-VstsTool.
[debug] Arguments: '/D /E:ON /V:OFF /S /C "CALL "C:\My Project\agent_work_temp\dde3e815-8cea-4bea-ab26-77e9bb52d973.cmd""'
[debug] FileName: 'C:\WINDOWS\system32\cmd.exe'
[debug] WorkingDirectory: 'C:\My Project\agent_work\1\s' "C:\WINDOWS\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\My
Project\agent_work_temp\dde3e815-8cea-4bea-ab26-77e9bb52d973.cmd""
Building SsisProject...
Microsoft Visual Studio 2019 Version 16.0.29306.81. Copyright (C)
Microsoft Corp. All rights reserved.
The following files were specified on the command line:
C:\My Project\agent_work\1\s\MySolution.sln My
Project\agent_work\1\s\ETL\Integration\MySsisProject\MySsisProject.dtproj
[debug]Exit code: 1
[debug]Leaving Invoke-VstsTool.
[error]Cmd.exe exited with code '1'.
[debug]Processed: ##vso[task.logissue type=error]Cmd.exe exited with code '1'.
[debug]Processed: ##vso[task.complete result=Failed]Error detected
[debug]Leaving C:\My Project\agent_work_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.151.2\cmdline.ps1.
The other generic trouble shooting advice is to remove the space in your "My Project" folder. Yes, it's 2019 and it shouldn't matter and many tools comprehend spaces but the fewer escapes you need to worry about, the better your chances of success.

Makefile Error after adding C mysql libs Eclipse CDT

I'm using Eclipse Juno CDT.
I added the following to my project:
the mysql/includes path to the includes path setting
the libmysql.lib and zlib.lib to libraries setting
the mysql library path to the library paths setting
Now, when I make my project, the compilation throws an error when I run the application.
This is the build:
10:08:56 **** Build of configuration Debug for project mysqlapp ****
make all
Building file: ../src/mysqlapp.c
Invoking: Cygwin C Compiler
gcc -I"C:\Program Files\MySQL\MySQL Connector C 6.0.2\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/mysqlapp.d" -MT"src/mysqlapp.d" -o "src/mysqlapp.o" "../src/mysqlapp.c"
cygwin warning:
MS-DOS style path detected: C:\Users\Yonaton\workspace\mysqlapp\Debug
Preferred POSIX equivalent is: /cygdrive/c/Users/Yonaton/workspace/mysqlapp/Debug
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Finished building: ../src/mysqlapp.c
Building target: mysqlapp.exe
Invoking: Cygwin C Linker
gcc -L"C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt" -o "mysqlapp.exe" ./src/mysqlapp.o
Finished building target: mysqlapp.exe
And this is the run within eclipse:
10:09:55 **** Incremental Build of configuration Debug for project mysqlapp ****
make all
src/mysqlapp.d:1: *** multiple target patterns. Stop.
10:09:56 Build Finished (took 225ms)
Under Project->Properties->C/C++ General->Paths and Symbols->Libraries do not add the file name of the library, nor the path.
So if you want to link against /lib64/libz.so just add z.
Or alternativly add the z under Project->Properties->C/C++ Build->Settings->GCC Linker->Libraries.
If the library is not located under a standard path add the custom search path for a library under Project->Properties->C/C++ General->Paths and Symbols->Libraries Paths.
Update (referring "multiple target patterns"):
make does not like DOS paths. In the .d file a : after the drive letter is interpreted as target delimiter.
Switch to UNIX paths (as you were already told to do ... ;-)).
(see also: "multiple target patterns" Makefile error)
If I remember correctly "-l" ( small L) before your libraries.

How to get CruiseControl.NET working with Mercurial: "Source control failure (GetModifications)"

I'm trying to set up CruiseControl.NET 1.5.7256.1 for automatic builds. My project is stored in Mercurial, and I'm using the following ccnet.config:
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<project name="Slider" webURL="http://localhost/ccnet">
<triggers>
<intervalTrigger seconds="3600" />
</triggers>
<sourcecontrol type="hg" autoGetSource="true">
<executable>C:\Python26\Scripts\hg.bat</executable>
<repo>c:\repos\slider</repo>
<workingDirectory>c:\ccnet\slider</workingDirectory>
</sourcecontrol>
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe</executable>
<workingDirectory>c:\ccnet\slider</workingDirectory>
<projectFile>Slider.sln</projectFile>
<buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
<targets>Slider</targets>
<timeout>900</timeout>
<logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
</project>
</cruisecontrol>
But when I force a build, I get this error:
[Slider:WARN] Source control failure (GetModifications): Source control operation failed: < was unexpected at this time.
. Process command: C:\Python26\Scripts\hg.bat log -r 0:123 --template <modification><node>{node|short}</node><author>{author|user}</author><date>{date|rfc822date}</date><desc>{desc|escape}</desc><rev>{rev}</rev><email>{author|email|obfuscate}</email><files>{files}</files></modification> --noninteractive
[Slider:INFO] Integration complete: Exception - 12/2/2010 1:19:08 PM
The error is presumably caused by the unquoted angle brackets in the --template parameter, but how can I make CC.NET put quotes around that parameter?
===============
Here's hg.bat:
#echo off
rem Windows Driver script for Mercurial
setlocal
set HG=%~f0
rem Use a full path to Python (relative to this script) as the standard Python
rem install does not put python.exe on the PATH...
rem %~dp0 is the directory of this script
%~dp0..\python "%~dp0hg" %*
endlocal
I'm successfully using CruiseControl.NET 1.5.7256.1 with Mercurial installed from this msi, using full path of hg.exe as the executable value.
In project\core\sourcecontrol\Mercurial\Mercurial.cs the template is used like this:
buffer.AddArgument("--template", HistoryTemplate)
and will be formatted for the command line like this:
string.Format("{0}{1}{2}", arg, separator, StringUtil.AutoDoubleQuoteString(value))
where the separator is " ", and AutoDoubleQuoteString will quote the template, so this can't be the cause of the error.
UPDATE 1
Actually, AutoDoubleQuoteString should quote the template, but in the current version doesn't do it. Also, even if the build succeeds when using hg.exe, running the actual command line in a command prompt returns the same error.
UPDATE 2
CruiseControl.NET 1.6.7981.1 was just released (see release notes), and since the template is now passed as a file, it works just fine (at least on my PC).