manage Jenkins build status - batch-file

I'd like to run batch using jenkins. And the status of build depends of number of files created in a specific folder. My question is how could I manage Jenkins build status depending of number of files created?

You can execute a shell script to count the files and return 1, if the count isn't expected.
Another way would be to use the Text-finder Plugin searching for a pattern in the console log.
Groovy Postbuild Plugin is another alternative:
buildUnstable() - sets the build result to UNSTABLE.
If you like to use the CLI you can use the following command:
java -jar jenkins-cli.jar -s http://...:8080/ set-build-result
Sets the result of the current build. Works only if invoked from within a build.

Related

Jenkins parameter is getting replaced by a white space

I have a parameterized build (copied from an existing job) in Jenkins. While building, my parameter is getting replaced by a white space. Here I am sharing what I have.
Parameter Name: BuildDate (I tried using %% and ${} but no luck)
Windows batch command:
copy \\Network_drive\dir1\dir2\dir3%BuildDate%\filename*.zip .
Output from Jenkins console:
c:\jenkins\workspace\my_build_job_name>copy \\Network_drive\dir1\dir2\dir3\ \filename*.zip .
\\Network_drive\dir1\dir2\dir3\ \filename*.zip
The system cannot find the path specified. 0 file(s) copied
c:\jenkins\workspace\my_build_job_name>exit 1
Build step 'Execute Windows batch command' marked build as failure
Notifying upstream projects of job completion Finished: FAILURE*
Note: We have a Windows/Linux mixed environment. Whenever we want to run shell scripts, we use Cygwin, batch should directly run.
Finally it turned out that one of the parameters was not populating due to hitting "rebuild last". Re-running the whole pipeline did it work. I still wonder why it was not populating but its all hood now!!!

Jenkins -Gradle -Java

I am trying to parameterize my build in Jenkins by taking two variables and pass it to gradle build file which should finally be used by my java file. How could I achieve this?
See Jenkins, Parameterized Build:
Sometimes, it is useful/necessary to have your builds take several "parameters".
[...]
The parameters are available as environment parametersvariables. So e.g. a shell ($FOO, %FOO%) or Ant ( ${env.FOO} ) can access these values.
[Correction by me.]
Those variables are available throughout the build so your Gradle build file can use them.

Post-build arguments to batch script fails to convert build parameter

I'm using TFS 2013 and am building an Azure Cloud Service project that I want to package with Nuget so that I can publish to Octopus Deploy. I can't use octopack, because at the moment this is not supported. I'm trying to pass TFS parameters into a post-build batch script so that I can run nuget with -version parameters (which should change with each build).
The problem I'm having is that the batch script does not recognise the TFS build parameters. for example, in the script I want to pass an argument version $(TeamProject)-1.0.0$(Rev:.r), that would give the script the version to set in the package name.
The full nuget package call in the script is:
%nugetPath% push %packagePath%\Veedyo.%version%.nupkg
Passing this into the post-build script path works:
$/Application1/MAIN/Source/.NET/Application1.Package/package.cmd
This is because the source control path is translated into an actual path just after the build completes (and I can see the real path in the log).
However, the Post-build script arguments property in the build, doesn't convert this "$(TeamProject)"-1.0.0"$(Rev:.r)" to the desired value. this leads to an error executing the batch script:
Exception Message: TF270015: 'package.cmd' returned an unexpected exit code. Expected '0'; actual '1'. See the build logs for more details
So, does anyone have any idea how to convert add build parameter to the post-build script arguments property?
These macros are not available when you run the script. You can use one the the TF_BUILD environment variables listed here.
Probably, you are looking for TF_BUILD_BUILDNUMBER, or maybe you have to extract the data you are looking for; in this latter case Powershell can be simpler to use than cmd.exe interpreter.

Jenkins Post Build Task access jenkins environment variables like JOB_NAME

I want to get the job details in Post Build Task plugin and pass the details to the batch/ powershell for further processing.
I am not able to access the Jenkins environment variables like JOB_NAME, JOB_ID etc.
In Post Build Plugin task
Log text "BUILD SUCCESSFUL"
OPTION
Script Block:
run.bat $JOB_NAME-$JOB_ID
I need to pass the $JOB_NAME-$JOB_ID to the script.
Build Parameters are accesses as $Name in the Execute shell and post build section.
You can use
$JOB_NAME
$BUILD_NUMBER
for name of job and build number which is same as JOB_ID.
Also Set "Jenkins user build variables" to get more info regarding Environment variables.
Generally the sintax for accessing variables is the following:
${VARIABLE}
but in some cases, especially when you are trying to access variables using during the build, this sintax can be used:
${ENV, var="VARIABLE"}
That in my case is working also when you have a parameterized build.

Bash - MSBuild - File Logger

I'm trying to improve our local build implementation, by using Bash and pending the success of a solution build, run the unit tests.
At the moment I want to pipe the results of the build in quite mode to the console (using default console logger) but pipe the results in more detail to a file using the file Logger.
From the bash I can execute the build fine, providing I don't specificy the FileLogger.
C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe /verbosity:q D:/MyDocs/Main.sln
The minute I do this :
C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe /verbosity:q D:/MyDocs/Main.sln /logger:FileLogger,Microsoft.Build.BuildEngine; /flp:logfile=Build.Log
The build fails and I get a could not load file or assembly Microsoft.Build.BuildEngine.
I've also tried changing dir so that I'm in the framework directory, but still get the same error.
As an aside I'm trying to provide the devs's with a quite verbosity for the local builds, but enable auto execution of the tests if the build is successful. I'll analyse build success by reviewing the contents of the Build.Log file for "Build Succeeded" Or "Build Failed"
I tried pushing the result to file using > "Build.log" but that impacts the colouring of the build output on the console which diminishes some of the value of what I'm trying to achieve.
Any help would be great.
Thanks
Microsoft.Build.BuildEngine is a namespace and not an ILogger. If you replace that portion in:
/logger:FileLogger,Microsoft.Build.BuildEngine;
... with a valid ILogger it's more likely to work.

Resources