Anyone manage their Continuous Integration with TeamCity, FinalBuilder, and Mercurial (Kiln)? [duplicate] - mercurial

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Continuous Integration stack on Windows with Mercurial + Mercurial Queues?
If so, what does your build process look like?
I'm having a difficult time (mostly because of my lack of experience/understanding of all 3 tools) getting TeamCity to run my FinalBuilder scripts. Right now I have FinalBuilder managing all the source control checkouts and TeamCity basically just running the FinalBuilder script and reading in the NUnit test results, but it doesn't work due to authentication errors while executing mercurial commands to kiln.

If you've installed the Kiln Client on the machine running your FinalBuilder script, you'll have access to the "kilnauth" mercurial extension that should solve this problem for you.
Just log on to the build machine as the user that runs the FinalBuilder script and manually execute one push or pull command from the Mercurial repository you're trying to use, you'll be asked to authenticate. Authenticate once, and the Kiln Client extensions will remember this authentication for this user...and any subsequent runs by the FinalBuilder script should authenticate just fine.
Does this solve the problem for you? It's the best solution as it doesn't store any username or password on your machine. There are obviously other possibilities, like changing the path of your Mercurial to use the format http://{username}:{password}#{kiln url}...but this isn't as nice or safe as the technique above.
Does this make sense?

I don't know anything about Kiln, but I've just started working for VSoft and am working on a Mercurial action for the next version of FinalBuilder. Hopefully some of this will help.
Are you athenticating via SSH or SSL? Can you pull/push to the repository from the command line? Pretty much anything you can get to work from the command line should be possible with FinalBuilder.
To authenticate to BitBucket via SSH, I did the following:
download puttygen and pageant
create a new SSH key in puttygen
add the private key to pageant
add the public key to BitBucket
From there, I can successfully
hg push ssh://hg#bitbucket.org/user/repo
NB, I also have TortoiseHG installed, and Mercurial is using TortoisePlink as the ssh client.
If you're using SSL, you can store the username/password combo in your FinalBuilder action. To turn a TextEdit box into a password field, change the PasswordChar property from #0 to *. Then in the ReadData event, add something like
Page.tbPassword.Text = DecryptString(Properties.PropertyAsString("Token"));
and in the WriteData event, add
Properties.PropertyAsString("Token") = EncryptString(Page.tbPassword.Text);
When you add the Token property to your action, tick the Property is Hidden from Action Inspector and Property is Read Only in Action Inspector options.
To generate your repository string, you'll want to do something like this in the Action's GetCommandLine event:
var repo = Context.Properties.PropertyAsString("Repository");
var username = Context.Properties.PropertyAsString("Username");
var password = DecryptString(Context.Properties.PropertyAsString("Token"));
var repo = "ssh://" + username + ":" + password + "#" + repo;
CommandLine.AddArgument("push", repo, qtNone);
NB, I haven't tested that code, but hopefully it gives you an idea.

Related

SourceTree - Mercurial - Authentication - requesting user name and password each time?

I use SourceTree with a local Mercurial server, the problem is that SourceTree is asking to authenticate at each operation. By example, for a clone it can be 10 times entering user/pwd ...
Though, I enter user/pwd and checked the "remember" checkbox, it continue to ask.
I have see that I can use SSH, but I have no access to the repository web page (it is a local server) to setup the SSH key.
1 - I tried to setup an account in SourceTree using Options>Authentication
Using the option "Bitbucket server" and entering our server URL. In fact, with this method I can even enter my password, it just failed !
2 - By using an URL like this : https://username:password#serverurl
3 - Using the Windows Credentials Manager !
4 - I edited the .hgrc file
Does someone has an idea ?
I was unable to solve the issue, then I use TortoiseHG and this tool works !
So, it looks like a bug in SourceTree !
You can also switch for SourceTree version 1.6.23, this one will work.
This solution on the Atlassian Community solved the issue for me (edited for typos and clarity):
For all who are using SourceTree under Windows OS and Mercurial as Versioning tool and want to get rid of the boring popup asking for your credentials:
Start cmd shell as admin
Change path to where git-credential-manager.exe as been installed (normaly under ~\AppData\Local\Atlassian\SourceTree\git_extras)
Call "git-credential-manager.exe store"
In the next lines fill in:
protocol=https
host=code.domain.name
username=yourLoginName
password=yourLoginPassword
Press return again for a new empty line. If you don't get any message, everything is okay.

How to setup Authorization Hudson /Jenkins to clone your mercurial repository

After installing and playing around with mercurial , I am trying to get Hudson to clone the repository so it can build my project.
At the moment the following task works.
I Can sync to my external host and the code shows up on that host.
Now I am trying to configure hudson / jenkins to access the code on my host.
But unfortunately I am rolling on a error:
Started by user anonymous
$ hg clone --rev default https://bitbucket.org/*/testproject "F:\Hudson\jobs\testproject\workspace"
abort: http authorization required
ERROR: Failed to clone https://bitbucket.org/*/testproject
[workspace] $ hg log --rev . --template {node}
java.io.IOException: Cannot run program "hg" (in directory "F:\Hudson\jobs\testproject\workspace"): CreateProcess error=267, The directory name is invalid
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:698)
at hudson.Launcher$ProcStarter.start(Launcher.java:329)
at hudson.Launcher$ProcStarter.join(Launcher.java:336)
at hudson.plugins.mercurial.MercurialSCM.joinWithPossibleTimeout(MercurialSCM.java:298)
at hudson.plugins.mercurial.HgExe.popen(HgExe.java:191)
at hudson.plugins.mercurial.HgExe.tip(HgExe.java:171)
at hudson.plugins.mercurial.MercurialSCM.calcRevisionsFromBuild(MercurialSCM.java:254)
at hudson.scm.SCM._calcRevisionsFromBuild(SCM.java:304)
at hudson.model.AbstractProject.calcPollingBaseline(AbstractProject.java:1186)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1175)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:523)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:418)
at hudson.model.Run.run(Run.java:1362)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:145)
Caused by: java.io.IOException: CreateProcess error=267, The directory name is invalid
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 18 more
Finished: FAILURE
What actions do i need to do to tell Hudson to use username x and password y to acces the data?
Edited => Found how to integrate ssh .
Used SSH instead of https
Download putty.exe, puttygen.exe, pageant.exe, and plink.exe from the PuTTY website.
Start puttygen and generate a key in OPENSSH FORMAT (hudsons format) (=> How to use Svn + SSH )
Click the Save private key button and save the .PPK file somewhere.
Click the Save public key button and save it.
Go to your website and enter the public ssh-key
Run pageant.exe. The pageant icon (a computer wearing a hat) will show up in the status tray.
Right-click the pageant icon and choose Add Key.
Choose the .PPK file you saved earlier and type in its passphrase.
The following (end part is copied) from Ted Naleid (Thank you!) blog witch can be found here : Hooking up hudson to your ...
Install the Mercurial plugin in Hudson
All that’s left to do now is install
the Mercurial plugin in hudson. In a
browser, go to
http://INSERT_YOUR_IP_HERE:8080.
Hudson should come up.
Click on “Manage Hudson” and go to
“Manage Plugins”. Go to the
“Available” tab, check “Hudson
Mercurial plugin” and hit the
“Install” button. Hudson will prompt
you to restart, and then it’s
installed.
After that, just create a new job and
you’ll have a new “mercurial” option
in the “source control management”
section. Select that and put the ssh
URL in the “Repository URL” field.
Then put “default” in the “branch”
field and set up the rest of the job
to build/test your code (an exercise
left to the reader).
and here it is the first succesfull build !
Conclusion : This is a summary of all the small blogpost scattered arround the internet. I hope this post helps you in starting hudson and mercurial.
I think the problem is not related to username and password. Your stacktrace tells you there's something wrong with the path F:\Hudson\jobs\testproject\workspace.
Cannot run program hg (in directory
"F:\Hudson\jobs\testproject\workspace")
The directory name is invalid
Anyway, you can specify the username and password in the URL like: http://user:password#mydomain.org.
To authenticate the Jenkins/Hudson Mercurial plugin with BitBucket I too found it useful to use the SSH protocol instead of HTTPS particularly since:
there doesn't seem to be a way to store your HTTPS credentials to BitBucket with the Mercurial Jenkins plugin, but with SSH you can safely and securely store your credentials
with SSH you can configure it to use compression, which Mercurial doesn't do natively.
Good instructions for setting up SSH access to BitBucket are available here: http://confluence.atlassian.com/display/BITBUCKET/Using+SSH+to+Access+your+Bitbucket+Repository
Notes:
If you are running Jenkins/Hudson on a *nix server, you will want to login as the user running the Jenkins process and perform these operations from that users home directory, so the configurations will be found by that user (e.g. on my Debian server installation of Jenkins standalone, the user 'jenkins' is created and the home directory is set to '/var/lib/jenkins' [not /home/jenkins] - where I performed the instructions provided at the above link).
I found it very helpful to assure the hg clone command worked from the command line before attempting to have Jenkins call it.
IMPORTANT: In order to get this to work, I had to generate a key ** without ** a passphrase.
You can add the following lines to jenkins .hgrc file (usually /var/lib/jenkins/.hgrc)
[auth]
bitbucket.prefix = https://bitbucket.org/your_user/...
bitbucket.username = your_user
bitbucket.password = ******
See http://www.selenic.com/mercurial/hgrc.5.html#auth
You can add your scm credentials in the 'Credentials` section of Jenkins:
Also change the job configuration to use the credentials:

Mercurial: can't host on BitBucket.org with an error SSH, OpenSSH?

For a new project :
I created a new repo inside the project's folder.
I created a new repo on bitbucket.org
Now I have one local repo and one remote repo. So I should not need to clone. I push from the local to remote.
In Repository Explorer, I fill the URL and "push outgoing changesets". No login and pwd asked? I get this error error SSH-2.0-OpenSSH_5.3
Previously I cloned a HG project on bitbucket.org with no problem.
Is there any conflict with the previous repo? Where should I input the login and password?
I changed in the Global Settings > Proxy
Host : https://bitbucket.org/$myaccount
user :
password :
Should I use a proxy ? Still something wrong with error SSH-2.0-OpenSSH_5.3
That error is telling you that the path you're trying to push to on bitbitbucket doesn't match the repository you created there. Perhaps you've got a typo in your username or your project (case matters for both). The easiest way to get that URL is to copy it right off of the bitbucket page for that repo.
People's confusion in your wording comes from this statement "I want to push (by cloning) my local repo". Pushing and cloning are separate operations. Cloning creates a new repository and pushing moves changesets between two already existing repositories.
If you do have a repo locally and remotely already then you want to push but not clone, and you need to get the URL right to do it.
Eureka, I found it.
I filled something in Global Settings > Proxy so that I won't need to re-authenticate each time.
This was the cause of the infamous error SSH-2.0-OpenSSH_5.3 . That was stupid I know.
What I should have done is :
First uncheck the proxy settings.
Second I'm too lazy to input my authentication , I should configure paths (Hg Repository Explorer > Synchronize > Configure paths) to save the URL . But still now I don't know how to save my login and pwd . But NOW it WORKS

Hudson svn credentials

How to enter subversion credentials in Hudson by shell?
I've tried to generate file hudson.scm.SubversionSCM.xml in HUDSON_HOME and reload configuration, but changes weren't applied.
The easiest way to enter a credential from the shell is to use "svn" executable. Hudson recognizes the ~/.subversion/auth directory that it creates.
Under Windows the global credenentials are stored under %APPDATA%\Subversion\auth. The following Groovy code helps generating these credentials:
SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url))
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(SVNWCUtil.defaultConfigurationDirectory,"AD\user","password",true)
repository.setAuthenticationManager(authManager)
repository.getDir("", -1, null ,(Collection)null) // or some random SVN operation
Libraries used in the code above (example in Gradle):
compile 'org.tmatesoft.svnkit:org.tmatesoft.svnkit:1.7.8'
compile 'net.java.dev.jna:jna:3.4.0' // so wincrypt is available
Make sure you run the code with the same user Hudson runs on the Windows machine.
Just start with the Hudson.
Install all required Plug-Ins.
Hit the link,EX:-localhost:8080/hudson
Click on the add job/Create job.
While choosing the options SVN will be present there,Give the SVN location.
Credentials link is present out there.Click on that link.
A form will get open,provide valid credentials for that location of SVN.
Observe the Success message on the screen and then get back to the Create job,Complete with Job creation and Build the task.

How to configure hosted Mercurial in TeamCity 5

This is probably a simple problem and I'm feeling exceptionally dumb because I can't find a any kind of documentation.
I've just installed TeamCity 5 and I want to get files from my Mercurial hosting and there is two fields I just can't figure out.
HG Command path. What should I put here? The path to a file containing what? Can I get an example of that file somewhere?
The host is using Mercurial over SSH where do I define my private key?
Pull changes from? Should I put the address I'm cloning from i.e. ssh://username#myhost.something/project
I figured this out for my TeamCity 5 server last week.
HG Command path: HG
Pull changes from: https://bitbucket.org/.../.../
Don't put the username# in the URL. This is specificed as in the Username/Password fields. If you include the username in the URL it'll fail as there is a bug in the configuration tool. You'll also see a screenshot of the configuration attached to the thread:
http://www.jetbrains.net/devnet/message/5254640#5254640
I'd suggest getting things working with HTTPS and then moving to SSH if possible. This breaks things down into two easier to solve configuration problems. I used the following tutorial to get SSH going on my Windows client machine.
http://www.codza.com/mercurial-with-ssh-setup-on-windows
I've not set this up on my TeamCity server yet. However I did get TeamCity to pick up my Mercurial.ini settings by putting the ini file in \Documents and Settings\TeamCity, which is the account the service runs under.
I've not used team city, but I think hg command path is probably the full path to your local mercurial executable. For me (on linux) that's:
$ type hg
hg is /usr/bin/hg
On windows it's where the 'hg' executable in your system path was placed by whichever (of the many) windows installers for mercurial you used.
Pull changes from sounds like the URL to the repo, so:
ssh://username#myhost.something/project
or
ssh://username#myhost.something//project # note the _two_ double slashes
if you're using absolute paths on the server side.
Your private key location/specification depends on what you're using for ssh and whether or not you're running ssh-agent, but here's a links that explicitly points from within mercurial.ini, which seems sound:
http://dev.openttdcoop.org/projects/home/wiki/Configuring_TortoiseHg_(Windows)#Pointing-to-you-Private-key