Skip to content

Commit

Permalink
Add support for 'setParameter' service message to TeamCityProvider + …
Browse files Browse the repository at this point in the history
…supporting tests
  • Loading branch information
kcamp authored and gep13 committed Jul 25, 2016
1 parent 318e80e commit 2951f9d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Cake.Common.Tests/Unit/Build/TeamCity/TeamCityProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,23 @@ public void Should_Use_Provided_DotCover_If_ToolPath_Is_Not_Null()
fixture.Log.AggregateLogMessages());
}
}

public sealed class TheSetParameterMethod
{
[Fact]
public void SetParameter_Should_Write_To_The_Log_Correctly()
{
// Given
var fixture = new TeamCityFixture();
var teamCity = fixture.CreateTeamCityService();

// When
teamCity.SetParameter("internal.artifactVersion", "1.2.3.4");

// Then
Assert.Equal("##teamcity[setParameter name='internal.artifactVersion' value='1.2.3.4']" + Environment.NewLine,
fixture.Log.AggregateLogMessages());
}
}
}
}
14 changes: 14 additions & 0 deletions src/Cake.Common/Build/TeamCity/TeamCityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ public void SetBuildNumber(string buildNumber)
WriteServiceMessage("buildNumber", buildNumber);
}

/// <summary>
/// Tells TeamCity to set a named parameter with a given value
/// </summary>
/// <param name="parameterName">The name of the parameter to set.</param>
/// <param name="parameterValue">The value to set for the named parameter.</param>
public void SetParameter(string parameterName, string parameterValue)
{
WriteServiceMessage("setParameter", new Dictionary<string, string>
{
{ "name", parameterName },
{ "value", parameterValue }
});
}

private void WriteServiceMessage(string messageName, string attributeValue)
{
WriteServiceMessage(messageName, new Dictionary<string, string> { { " ", attributeValue } });
Expand Down

0 comments on commit 2951f9d

Please sign in to comment.