vicky
vicky

Reputation: 35

Jenkins build number issue

I have posted the question once but I think it was incomplete information.. Here is my question..I am new to jenkins. I am running a free-style project in jenkins. Previously I was using BuildForge for all my builds.

The issue is, there is a Properties file say abc.properties file. It contains

Buildnumber=0

Previously I was using an xml and BTM file through which "BuildNumber" gets in sync with current build number. The code of BTM file is

echo build.number=%ABCBuild redirect to: c:%BUILDBASEDIR\myfile\ABCbuild.number echo build.number=%ABCBuild

c:%BUILDBASEDIR\myfile\ABCbuild.number echo build.number=%ABCBuild redirect to: c:%BUILDBASEDIR\myfile\GUIbuild.number echo build.number=%ABCBuild > c:%BUILDBASEDIR\myfile\GUIbuild.number echo collector.build.number=%1 redirect to: c:%BUILDBASEDIR\myfile\filebuild.properties echo collector.build.number=%1 > c:%BUILDBASEDIR\myfile\filebuild.properties echo collector.build.type=indiv append to: c:%BUILDBASEDIR\myfile\filebuild.properties echo collector.build.type=indiv >> c:%BUILDBASEDIR\myfile\filebuild.properties echo.

And it create a zip file in which the abc.properties file contains the build number.

Steps involved in xml file are

Prepare:

safe-clean:

create-file:

create-current-file-qpack:

create-file-qpack:

build-file-qpack:

create-current-file-rpack:

create-file-rpack:

build-file-rpack:

prepare-anystudio:

fill-file-props:

create-current-file:

    <target name="create-current-file" depends="prepare-anystudio,fill-file-props">
    <property name="file.name" value="${file.name}"/>
    <property name="file.version" value="${file.version}"/>
    <property name="file.path" value="${file.path}"/>

    <echo message="Building file ${file.name} version ${file.version}......."/>

    <delete dir="${cur.dirname}/${dir.final}/files/${file.name}"/>
    <echo message="-sourcefiles ${file.path}/${file.name} -output            ${cur.dirname}/${dir.final}"/>
    <java dir="${cur.dirname}/${dir.filestudio.exec}"
          classname="com.comp.cas.ucf.configtool.DistributionUtil" failonerror="true"     fork="yes">
        <classpath refid="classpath.studio"/>

Build Steps involved in jenkins are

Wipe-Out the workspace

Perforce Sync

Run Batch Command

Invoke Ant (Steps mentioned earlier)

Build Successful

Run Post Build Script (Batch)

makdir

creates zip

I have written the batch file to replace the current build number. But after the ANT runs Its always a Game Over situation because it don't updates the file. The Batch script is

Batch script I am using is.

@echo off

call :FindReplace "Buildnumber=0" "Buildnumber=%BUILD_NUMBER%" abc.properties exit /b

:FindReplace <Buildnumber=0> <Buildnumber=111> <collector.properties>
set tmp="%temp%\tmp.txt" If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (   for /f
"usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
<%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
if exist %tmp% move /Y %tmp% "%%~dpnxa">nul   ) ) del %temp%\_.vbs exit /b

:MakeReplace

%temp%_.vbs echo with Wscript

%temp%_.vbs echo set args=.arguments %temp%_.vbs echo .StdOut.Write _ %temp%_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1) %temp%_.vbs echo end with.

Now Please can someone tell me.. How I can put the buildnumber in the zip file. Yeah the zip file is created at a local repo path and not in the workspace.

I am using Perforce for all my code check-in and sync.

I think the "Create-current-file" is filling my file and properties file as well.

Please help. I want to use the similar logic in jenkins so that I can have the build number in the zip file as well. The script above is really helpful It changes the build number in the workspace but not effective as after the ANT INVOKES the game changes and I got the buildNumber as 0 because the buildnumber in perforce is always 0.

Note: ANT get its file from the workspace where P4 has store it.

What needs to be done. Please help, I already spend three days on it.

Upvotes: 0

Views: 787

Answers (1)

HX_unbanned
HX_unbanned

Reputation: 597

You don't need any magic or scripting assests to get build number, if you use this value within one project. ;)

Each (and any kind of jenkins supported project types) job ( IMHO ) has ability to use Environment Variables.

See this link: http://<your_build_server_name>/env-vars.html/? as example.

As long as you use SCM and Build SCripting ( Maven, Ant, ? ), you can freely use them. If called from windows batch, access them using %%, not ${} syntax. ;)

Upvotes: 0

Related Questions