3

I am using Jenkins, Ant , Flex and Java for my web application. Currently I update a build version file in Flex src and commit it before starting Jenkins build. I want to avoid this manual process and let script do this for me.

Contents of file:

Build=01_01_2013_10:43
Release=2.01

Question1: I want to update this file contents and compile my code and then commit this file back to svn. So that SVN has latest build version number.

How do I commit this changed file to SVN. Would be great if commit happens after successful build.

Question2: I want to send an email to all developers an hour before build starts. "Please commit your changes. Build will start in 1 hr." Can I set up a delay between email and (actual svn export + ant build).
or
Do I have to schedule 2 jobs an hour apart. One to send email and one to do build.

user418836
  • 847
  • 3
  • 8
  • 19

2 Answers2

5

You can use the subclipse svn ant integration to commit changed files to SVN including authentication:

<svnSetting
      svnkit="true"
      username="bingo"
      password="bongo"
      id="svn.settings"
  />
<svn refid="svn.settings">
    <commit file="your.file" />
</svn>

To get username and password to the build file you have different options. One would be to use a parametrized build, where you define user name and password as build parameters which can be evaluated in the build file.

      username="${parameter.svn.username}"
      password="${parameter.svn.password}"

A second option is using a the jenkins config file provider plugin. With this you can also use the parameters like for the parametrized build, but you import the credentials from the provided config file, e.g. a properties file can be imported via

<property file="config.file" />

Actually you can also use ant's exec task to execute your subversion commit the file.

For sending an e-mail one hour before actually building, you should setup two jobs, which are scheduled one hour apart. But I don't think this is good practice to notify before building, consider to build more often maybe even per commit to svn.

Markus
  • 2,071
  • 4
  • 22
  • 44
  • Thanks @Markus. We are currently not planning for CI. Our Flex project build takes nearly 15 minutes and most of changes are simple UI changes. We are currently doing a scheduled build per day. – user418836 Apr 07 '13 at 15:00
  • Would be nice if you accept the answer if it is valid for you. – Markus Apr 07 '13 at 15:11
  • How do I get username and password to the svn. I know jenkins stores these credentials per job. How do I pass these credentials to build file. – user418836 Apr 09 '13 at 03:58
  • This means I must have username and password in build file. I need a way to pass username and password from Jenkins to build file and not hardcode in build file. The same svn credentials which I give during jenkins project should be passed over to build file as parameters. – user418836 Apr 10 '13 at 04:49
  • 2
    Jenkins polls "repo_a" for changes and builds it whenever change occurs, the build process commits back to "repo_a" (if build was successful) by updating a version file.. Wouldn't this create an infinite loop? – Bhavneet Singh Bajwa Sep 18 '14 at 07:50
1

You can also use the Post build Task plugin (https://wiki.jenkins-ci.org/display/JENKINS/Post+build+task) to execute svn as a shell script (svn must be installed and authenticated from the shell once for the user that runs Jenkins).

Then the svn commit runs as a post build action. The plugin has an option (checkbox) to run the script only if the previous build/steps were successful.

The plugins is also mentioned here: Execute Shell Script after post build in Jenkins

Community
  • 1
  • 1
Jan Ziegler
  • 106
  • 1
  • 4