odez213
odez213

Reputation: 723

Forcebuild CruiseControl.net from remote command line

Is there a command line switch to forcebuild cruisecontrol.net remotely. I am trying to avoid going to cctray and forcebuilding it manually every morning. It seems I have to create custom hook on the CruiseControl server by creating my own custom web service.

Upvotes: 1

Views: 2809

Answers (7)

grenade
grenade

Reputation: 32179

You can trigger directly by submitting a HTTP post. No need to create a separate URL or URL trigger. If Powershell is an option, this works for us (note that our builds have parameters which ccnet prefixes with "param_" in the post variable names, you can omit or tailor the parameters with this prefix for your needs):

function Build-CCNetProject {
    param(
        [string] $hostname,
        [string] $server,
        [string] $username,
        [string] $password,
        [string] $project,
        [string] $param_environment,
        [string] $param_build_version,
        [string] $param_request_id
    )
    $securePassword = ConvertTo-SecureString "$password" -AsPlainText -Force
    $credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword)
    $postParams = @{projectName="$project";serverName="$server";ForceBuild='Force';param_environment="$param_environment";param_build_version="$param_build_version";param_request_id="param_request_id";submit='Build'}
    $postUrl = "http://{0}/ccnet/server/{1}/project/{2}/ViewProjectReport.aspx" -f $hostname, $server, $project
    Invoke-WebRequest -Uri $postUrl -Method POST -Body $postParams -Credential $credential
}
# Usage:
Build-CCNetProject -hostname "teamcity" -server "somehost" -username "foo\bar" -password "baz" -project "awesome-app" -param_environment "uat" -param_build_version "1.0.1.123" -param_request_id "1"

Upvotes: 0

thewpfguy
thewpfguy

Reputation: 824

I had a similar requirement - to trigger a project from Nant/C# code. With the help of fiddler found out what was happening when we click on 'Force Build' on the Project's web dashboard.

You can send this URL to the build server. Do note the parameters in URL"ForceBuild=Force".

http://your-build-server/ccnet/server/local/project/your-project-name/ViewProjectReport.aspx?ForceBuild=Force

The "local" in the URL could vary depending on your configuration. For that, first try to fetch project report from CCTray and see what is the URL of your Cruise Control.NET project. Based on the URL modify it to trigger the project.

Good luck!

Upvotes: 1

ThiagoAlves
ThiagoAlves

Reputation: 898

Run this in the same directory of the ccnet.config file

"C:\Program Files (x86)\CruiseControl.NET\server\ccnet.exe" -r off -p [Project Name]

Upvotes: 1

Craig
Craig

Reputation: 11

There is a tool called CCCmd which is included in the CC.NET installer. This is a command-line interface that allows forcing a build remotely.

Upvotes: 1

aolszowka
aolszowka

Reputation: 1390

What about writing a Powershell Wrapper around ThoughtWorks.CruiseControl.Remote.dll? We do something very similar in a project we call CruiseHydra which emulates the ability to split multiple tasks across several build servers. I have attempted to extract the portions that should be relevant to you here. Please note that I have not tested this exact code, our library wraps this deep in its own abstraction, but the jist of it is here:

using ThoughtWorks.CruiseControl.Remote;

public ForceBuild(String ServerAddress, String projectToExecute)
{
  RemoteCruiseManagerFactory rcmf = new RemoteCruiseManagerFactory();
  ICruiseManager ccnetServer = rcmf.GetCruiseManager(ServerAddress);
  ccnetServer.ForceBuild(projectToExecute,"Forced By Programatic Wrapper");
}

You can obviously change the second argument to ForceBuild to be the name of your task. It's whats shown under the 'Integration Request' section on the dashboard.

Upvotes: 2

The Chairman
The Chairman

Reputation: 7187

What about splitting the problem? Set up a new CCNET project that has a PowerShell task and a ForceBuild publisher which triggers the original project:

<cruisecontrol>
  <project name="OriginalProject">
    <!-- ... -->
  </project name="NewProject">
  <project>
    <tasks>
      <powershell>
        <script>CreateDatabase.ps</script>
        <!-- ... -->
      </powershell>
    </tasks>
    <publishers>
      <forcebuild>
        <project>OriginalProject</project>
      </forcebuild>
    </publishers>
  </project>
</cruisecontrol>

In case you want to run the original project only if powershell task went through without any errors just move the forcebuild block from the publishers to the tasks section.

Upvotes: 0

Babak Naffas
Babak Naffas

Reputation: 12561

If you're building every morning, why not set up a schedule trigger instead?

UPDATE BASED ON NEW INFORMATION: If your Power Shell script can be modified to modify an internally accessible web page (update a time stamp text in the HTML), then you can use the urlTrigger

Upvotes: 1

Related Questions