We are conducting a database release in TFS SQL 2015. The plan is to concatenate and variables with strings. Error Message below,
For our deployment release, we have sqlpackage :
C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe
Method 1 :
/Action:Publish /SourceFile:"$(build.artifactstagingdirectory)"\Datawarehouse.dacpac
/Profile:"$(build.artifactstagingdirectory)"\Dev.Publish.xml
Method 2 (switching quotes to end):
/Action:Publish /SourceFile:"$(build.artifactstagingdirectory)\Datawarehouse.dacpac"
/Profile:"$(build.artifactstagingdirectory)\Dev.Publish.xml"
For some reason, TFS is not populating the variable in the logs. How do we conduct this? We want to concatenate a variable with a fixed string.
Error Message:
2018-12-13T18:43:49.0945356Z *** Error parsing connection string: Could not find a part of the path 'D:\testabcd....\$(build.artifactstagingdirectory)\Dev.Publish.xml'..
You may create simple cmd file like this:
echo off
echo 1: %1
echo 2: %2
echo 3: %3
Then copy it to work folder and add build step:
Result on my environment for the Method 1:
Method 2:
Related
My Jenkins instance is on Wondows. My file is on %JENKINS_HOME%/tools/tools-package-json-get-property/version.js
In Jenkins Script console I try this but do not work (groovy error).
println %JENKINS_HOME%/tools/tools-package-json-get-property/version.js
println "%JENKINS_HOME%/tools/tools-package-json-get-property/version.js"
println ("%JENKINS_HOME%/tools/tools-package-json-get-property/version.js")
echo %JENKINS_HOME%/tools/tools-package-json-get-property/version.js
Console error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: expecting EOF, found 'tools' # line 1, column 30.
println %JENKINS_HOME%/tools/tools-package-json-get-property/version.js
EDIT
I try println $JENKINS_HOME/tools/tools-package-json-get-property/version.js but I have this result error:
Console error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: expecting EOF, found '-' # line 1, column 34.
println $JENKINS_HOME/tools/tools-package-json-get-property/version.js
Use $ in starting of variable name instead of % . Grroovy understands java syntax only. Refer section 4.4.1 String interpolation of below link.
https://groovy-lang.org/syntax.html
new File("$JENKINS_HOME/tools/tools-package-json-get-property/version.js").eachLine { line ->
println line
}
This should work.
If you are using Windows , then you can just use type <filename> command to print the contents of a text file.
In Jenkins file just add below and you will see the contents in the console output:
bat "type $JENKINS_HOME\\tools\\tools-package-json-get-property\\version.js"
Note: For Windows I have used \\ instead of /
If you are running on linux, then you can just use cat <filename>
I followed the suggestions from this post on how to use the EnvInject plugin to create and set Jenkins environment variables. I'm using the "Inject environment variables" in post build step and set "Properties File Path"
The windows batch script create a environment variable OPS and writes it to a property file : results.txt which contains multiple lines , like :
OPS= This is line one,
This is two
This is three
Challenge: OPS picks up only the first line from results.txt and skips the rest of the lines.
How do I set OPS have all the lines as its value ?
cd C:\To\Test\Class\Path
java utilities.LogExtractor>ops.txt
#echo off
setlocal EnableDelayedExpansion
set LF=^
rem *** Two empty lines are required for the linefeed
FOR /F "delims=" %%a in (ops.txt) do (
set var=!var!!LF!%%a
)
set var=!var!!LF!
echo OPS=!var! > %JENKINS_HOME%\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\results.txt
and I set the "Properties File Path" to %JENKINS_HOME%\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\results.txt
From the source code, I'd say it uses java.util.Properties to load the file, calling the load method. The documentation says you can escape a line break with a backslash, so using
OPS= This is line one,\
This is two\
This is three
should be sufficient. (Be careful, whitespace at the beginning of the line is ommitted.)
I am executing parameterised build in jenkins to count no. of lines in file which has 1 file parameter. Its file location is pqr. The name of the script file is linecount.sh which is saved at remote server. When i tried to execute it using command sh linecount.sh filename, it works perfectly from jenkins. But as i remove filename from the argument and execute same script as parameterised build it is showing below error on console :
Started by user Prasoon Gupta
[EnvInject] - Loading node environment variables.
Building in workspace users/Prasoon/sample_programs
Copying file to pqr
[sample_programs] $ /bin/sh -xe /tmp/hudson3529902665956638862.sh
+ sh linecount.sh
PRASOON4
linecount.sh: line 15: parameterBuild.txt: No such file or directory
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I am uploading file (parameterBuild.txt) from my local machine. Why is it giving this error?
My doubt is in shell script I used argument as $1. How can I refer this when I am taking file as parameter.
The uploaded file will not retain the same name as it has on your local computer. It will be named after the File location argument specified in the file parameter settings:
In this example I will get a file called file.txt in my workspace root, regardless of what I call it on my computer.
So if I now build my job and enter the following in the parameter dialog (note that my local filename is table.html):
Then I get the following in the log (I have a build step which does ls -l):
Building on master in workspace /var/lib/jenkins/workspace/fs
Copying file to file.txt
[fs] $ /bin/sh -xe /tmp/hudson845437350739055843.sh
+ ls -l
total 4
-rw-r--r-- 1 jenkins jenkins 292 Feb 15 07:23 file.txt
Finished: SUCCESS
Note that table.html now is called file.txt, e.g. what I entered as File location.
So in you're case the command should be:
sh linecount.sh pqr
There is a a bug since ages that makes impossible to use fileParameter:
Handle file parameters
file parameter not working in pipeline job
There is a workaround for this issue https://github.com/janvrany/jenkinsci-unstashParam-library
and in a pipeline script you do:
library "jenkinsci-unstashParam-library"
node {
def file_in_workspace = unstashParam "file"
sh "cat ${file_in_workspace}"
}
If it's to do with Free-Style job & if your configuration looks similar to this - https://i.stack.imgur.com/vH7mQ.png then you can run simply do sh linecount.sh ${pqr} to get what you are looking for?
I am using a utility provided in Data Stage 9.1 diffapicmdline.exe to compare two jobs from different environment. I am using following batch script code to read the job names from text file in loop:
#echo off
SET var=
for /f "delims=" %%i in (grm_deploy.txt) do (C:\IBM\InformationServer91\Clients\Classic\diffapicmdline.exe /lhscd "/d=cs1cd:9080 /h=cs1i04 /u=user/p=password cs1cdhbi04/IST_GRM %%i" /rhscd "/d=cs1cd:9080 /h=cs1i04 /u=test /p=Pass cs1cdhbi04/TEST_NIMISH %%i" /t job /ot html /ol E:\compare_output.html)
echo this is the end
However I am getting following error:
D:\dataStage Components\Scripts>read_file.bat
Validating syntax of /lhscd.
Unknown flag specified 'jbLoadStgARxAR'
this is the end
Can anyone let me know what is going wrong over here?
In executing
secedit /configure /db %~1\tomcat.sdb" /cfg %~1\2003.inf" /log %~1\dtomcat.log" /quiet
where
%~1 == C:\Program Files\myDirectory\mySubDirectory\mySuperSubDirectory
a file titled "C:\Program" is generated and within the file is the output for calling
secedit /?
I am curious as to why this is occuring because it makes it quite difficult to start certain services after an installation of a new product, for instance a PostGres windows service.
You appear to be missing quotes in a couple of places:
secedit /configure /db "%~1\tomcat.sdb" /cfg "%~1\2003.inf" /log "%~1\dtomcat.log" /quiet
^ ^ ^
You need to enclose the pathname in quotes:
"C:\Program Files\myDirectory\mySubDirectory\mySuperSubDirectory"
The space in "Program Files" is treated as a delimiter.