user2297026
user2297026

Reputation: 65

Jenkins Mercurial How to get All files from all Changesets Included in Build

I'm quite new to Jenkins but as my project are starting to grow the need for a full CI increasing. So I'm looking to have a deploy task which will run if all passes. Now as Im using PHP for my server I don't want to publish via SSH the whole application each build. I would like to push only the files which have changed. Now in Jenkins I can get the revision but its showing me only the latest revision. I'm currently using batch file to get the variable value. What I need though is the list of changesets in the build as there could be more than one. Then use hg log -r %1:%2 --template "{file_mods}{file_adds}\n" to use from and too to get the list.

I am open to anyway to achieve this groovy/powershell or bat file. But any guidence on this would help as I'm getting somewhat lost looking through articles on the subject. I would have thought this would be a common thing so maybe Im missing something.

Thanks in Advance

Dean

Upvotes: 1

Views: 160

Answers (1)

Lazy Badger
Lazy Badger

Reputation: 97285

Just dirty ideas, not ready-to-use solution

Comments

I would like to push only the files which have changed

Obvious question|addition: "... changed since /this point in history/". You have to store somehow this data (latest changeset of deploy) and provide it to Jenkins job

use hg log -r %1:%2 --template "{file_mods}{file_adds}\n" to use

No. You can even at 1-st step use command, which'll prepare for you needed tree of files, and you have it: read hg help archive

Hints

  1. You can tag every passed tests and deployed changeset in order to have this information later. You can really use any format of tag (because latest tag will be always detectable as "latest", regardless of the name used), I recommend to select pattern, which will produce unique ids (just less headache in process), but you can have something like hg tag -f DEPLOY (-f for re-use existing name of tag, not the best style, but possible)

  2. With tagging at last step for successful deploy (not build) for any tag-pattern you can always have set of changesets for deploy in the next time: it will be range from latest tag to tip. It will be

    -r "last(tag()):tip"

  3. After all, you have command, which build tree of files to deploy, like

    hg archive "-Iset:status('last(tag())', 'tip', added() or modified())" -X .hgtags -rtip -tfiles "PATH/TO/ROOT/OF/TREE"

(notes: set construction define all files from range of changesets, read hg help filesets, last(tag()), tip is our range from above p.2, added() or modified() define which types have to be added to set: all changes, -X .hgtags exclude from archive file hgtags, which was modified since last tag-revision, but not needed on site)

  1. You still have one not solved problem: if you have files in working directory, which was removed during development, you have also somehow remove it on prod-server (hg archive can't handle this)
  2. Due to pp. 3-4, I'll recommend to think about "easy way of deploy": you can (?) have clone of repository on site-side, use working directory as site-root, and in this use-case deploy of new version to site will be super-easy as

ssh $SERVER

cd $SIE-ROOT$

hg up

Upvotes: 1

Related Questions