10
votes

When building from git on master jenkins fetches and uses origin/master. When building from git on a branch jenkins fetches and users mybranch not origin/mybranch and isn't picking up changes.

I switched the branch specifier to use origin/mybranch and it seems to work. Is the the standard way to handle things or am I missing a more obvious way of doing this? I don't want to add unecessary complexity.

Please let me know if jenkins should use origin/branchname instead of branchname for its Branches-To-Build field.

Thanks

Peter

2

2 Answers

3
votes

If you only have one remote repository (named origin), then entering branchname should be synonymous with entering origin/branchname. If you have multiple repositories and you just enter branchname then it should be checking all of the remote repositories for that branch.

Note that if you manually created a branch named branchname in the Jenkins workspace repository, then it may have slightly strange behavior, and you'll probably want to delete that branch or recreate the workspace. In general you should never manually manipulate the branches in the workspace repository.

It should never be trying to use local (non-remote) branches for polling or getting changes. If you are seeing it do this, then it's definitely a bug. You should try to upgrade your jenkins instance and git plugin to the newest version, and if you still see the problem you should file an issue (and in the meantime you could use origin/branchname as a workaround). However, entering just branchname works fine for me with the latest version, so if you continue to see this problem I would recommend you recreate the workspace to try to get a clean repository.

2
votes

Check your current .git/config, and you will see that your "origin" and how master relates to origin is already specified. No other branches will be specified, so the plugin can't construct a url. To add further branches...

[remote "origin"]
        url = ssh://myserv/srv/git/proj.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "im_a_branch"]
        remote = origin
        merge = refs/heads/im_a_branch_remote_branch_name

This would enable you to just put in the branch name in the branches to build field in Jenkins. That's probably overkill, and extra maintenance. Just put in the origin/branchname.