How to trigger a build for any branch in buildbot - buildbot

I am using buildbot in a project and I have a setup of a scheduler, that automatically builds the project every time when there is a change, to test whether it compiles fine. This works and buildbot detects the changes on all branches but the scheduler always builds the master branch, no matter which branch the change is on. I want it to build the branch that the change is on but I have trouble making that work. Here are the relevant parts of the buildbot configuration:
GitPoller:
c['change_source'].append(GitPoller(
repourl='git#git.somewhere.com:someproject.git',
branches=True,
pollinterval=60))
Scheduler:
c['schedulers'].append(AnyBranchScheduler(
name='all',
treeStableTimer=2*60,
builderNames=['builder 1', 'builder 2']))
This is a helper function that I use on several builders to checkout the code. I am almost always calling it with no parameters. Using the parameter is a rare case for a specific branch, and the above scheduler does not run such a builder. I assume that when I use no parameters, I am always running in the else block:
def CheckoutFactory(whichBranch = ''):
factory = BuildFactory()
if whichBranch:
factory.addStep(Git(repourl='git#git.somewhere.com:someproject.git', branch=whichBranch, mode='full', method='fresh', alwaysUseLatest=True, progress=True))
else:
factory.addStep(Git(repourl='git#git.somewhere.com:someproject.git', mode='full', method='fresh', alwaysUseLatest=True, progress=True))
return factory
What is wrong here? Am I doing something wrong and how do I make buildbot run the builds on the branches with the changes?
Configuration:
The buildbot master is running on XUbuntu 16.04.1 64-bit.
The buildbot version is 0.8.12. (from the repos)
Git is version 2.7.4. (from the repos)

I've fixed it. It seems that is not as automatic as I had thought. The branch has to be passed to the Git step, using the value of the branch property. I did it like this:
factory.addStep(Git(repourl='git#git.somewhere.com:someproject.git', branch=WithProperties('%s', 'branch'), mode='full', method='fresh', alwaysUseLatest=True, progress=True))
The relevant change is that this parameter has been added:
branch=WithProperties('%s', 'branch')
I am using the deprecated WithProperties and not Propery because that would trigger this problem, and I didn't want to change my configuration too much.

Related

Azure DevOps Release Pipeline - How to get the source code that was used to create the build artifact?

I have a continuously triggered Azure DevOps release definition that deploys a compiled Angular app to a web server and also runs Cypress e2e tests. The Cypress tests must run against the source code, so that means I need an artifact that is able to reference the same commit that was used to create the compiled app.
I created a GitHub artifact that gets the source code, but I can't figure out how to automatically change the branch/commit to whatever was used for the compiled app (it could be any branch and the names are not known ahead of time). Azure forces me to enter a hard-coded branch name and it does not accept wildcards or variables.
If I could simply use the variable ${Release.Artifacts.{alias}.SourceBranchName} for the default branch, I think I'd achieve my goal. Since Azure doesn't allow this, is there an alternative approach that accomplishes the same thing?
Note 1: The "Default version" dropdown has an option "Specify at the time of release creation", but that is intended for manual releases and can't be used for triggered ones, so no luck there.
Note 2: I looked into publishing the source code as an artifact, but it currently has almost 70,000 files and it adds more than an hour to the build step, so that also is not an option.
When you use the Release Pipeline artifacts, you are not able to set the pipeline variable in the Default branch field. This field only supports hard-coded.
is there an alternative approach that accomplishes the same thing?
The variable:$(Release.Artifacts.{alias}.SourceBranchName) can be used in the Release Pipeline agent job.
Workaround:
You can remove the Github artifacts and then add a Command Line task/PowerShell task/ Bash task to run the git command to clone the target repo.
For example:
git clone -b $(Release.Artifacts.{alias}.SourceBranchName) GithubRepoURL
PowerShell sample:
In this case, the script will use the same branch as Build Artifacts to checkout the source code.

Can we get files from a non Default branch?

I have a build pipeline that I want to trigger when the workspace_publish branch has changes to it, which is fine and this is currently working using these settings:
However, I want the Agent to extract the SQL Scripts (on the second step) from a different branch in the "Synapse Reporting" repository, NOT the workspace_publish branch.
Is this possible?
Actually this is fairly simple. You simply add another artifact to your pipeline that points to the source control branch you are interested in:
You then have 2 artifacts that are copied over and can be accessed during your release process.

Switch branch in TFS when executing tests from Jenkins

If I have multiple branches in TFS for my automation code (QA branch, Beta branch, Live branch, etc.), is there a way to switch the branch being used when executing the tests via Jenkins?
I use Eclipse IDE and have multiple Maven projects set up in Jenkins that execute my tests. We use TFS as our source control at the moment.
I have different automation branches due to code base differences between environments and would like to be able to specify the automation code branch to use depending on what environment is being ran against on build time in Jenkins.
I am using a Choice Parameter for the environment. If I could set another variable off of that, maybe something like if env.contains("Dev") then set branchPath="QA" and then use the branchPath as the Project path in Source Code Management?
You can specify the project path in Source Code Management section of Jenkin, in Project path, you can specify the branch you need:

How to trigger E2E tests when repositories are changed or pull requests added?

The only similar question I found is the following: Trigger travis ci builds if another git repository updates
Keep in mind that our E2E tests are full stack: we have a live server running, and our tests are run against the UI which hits the server. Nothing is stubbed or mocked.
Now, I can trigger in that way a travis rebuild, however problem arises when I have interdependency between branch and a different repository branch.
So let's say I have 3 repositories: backend, frontend and e2etests. If I create the new branch frontend/foo which requires also the backend/foo, there is no way e2e tests will ever pass because they will run one time with frontend/foo and backend/master and another time with frontend/master and backend/foo.
Did anyone face this problem previously? How did you deal with it?
After a lot of digging it was clear that there is no solution and everyone has their own built-in.
What worked for us is a git pre-push hook, environment variables pointing to our repositories and when you push it asks if you want to use a different branch for the UI project (if you are on the UI, asks if you want to use a different branch for the server project) and by default it uses the current branch for the project you are on. So it's quite fast on push, usually you'll just press ENTER an additional time, the two branches are basically the required dependencies and a travis build will be triggered with an API endpoint.
Works fine so far.

How to show TeamCity builds from non-default branch

I would like to to see all builds from a specific build type. To get them I am using this URL:
[team-city]/httpAuth/app/rest/buildTypes/id:[build-type]/builds
However, this only shows builds from the default branch. In my project I am using git-flow, so I do not have a single default branch. I have a lot branches, per feature/version. How do I get (by REST) builds for those branches?
I was just looking at a similar issue, i resolved it by including:
branch:(unspecified:any)
in this context:
/guestAuth/app/rest/builds/?locator=status:SUCCESS,number:<mybuildnumber>,branch:(unspecified:any)
Where mybuildnumber is self explanatory. This URL found a specific build i was looking for from non-default branch