Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying AzDO org in CreateAzureDevOpsFeed #7700

Merged
merged 7 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NETCORE_ENGINEERING_TELEMETRY>Publish</NETCORE_ENGINEERING_TELEMETRY>
<AzureDevOpsOrg Condition="'$(AzureDevOpsOrg)' == ''">dnceng</AzureDevOpsOrg>
</PropertyGroup>

<Target Name="Execute">
Expand All @@ -37,15 +38,17 @@
<CreateAzureDevOpsFeed
IsInternal="$(IsInternalBuild)"
AzureDevOpsPersonalAccessToken="$(AzdoTargetFeedPAT)"
FeedName="$(FeedName)-shipping">
FeedName="$(FeedName)-shipping"
AzureDevOpsOrg="$(AzureDevOpsOrg)">
<Output TaskParameter="TargetFeedURL" PropertyName="ShippingAzdoPackageFeedURL"/>
</CreateAzureDevOpsFeed>

<!--Create the nonshipping feed-->
<CreateAzureDevOpsFeed
IsInternal="$(IsInternalBuild)"
AzureDevOpsPersonalAccessToken="$(AzdoTargetFeedPAT)"
FeedName="$(FeedName)-nonshipping">
FeedName="$(FeedName)-nonshipping"
AzureDevOpsOrg="$(AzureDevOpsOrg)">
<Output TaskParameter="TargetFeedURL" PropertyName="NonShippingAzdoPackageFeedURL"/>
</CreateAzureDevOpsFeed>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PublishToMSDL Condition="'$(PublishToMSDL)' == ''">true</PublishToMSDL>
<PublishToSymbolServer Condition="'@(FilesToPublishToSymbolServer)' == '' and '@(PackagesToPublishToSymbolServer)' == ''">false</PublishToSymbolServer>
<PublishSpecialClrFiles Condition="'$(PublishSpecialClrFiles)' == ''">true</PublishSpecialClrFiles>
<DryRun Condition="'$(DryRun)' == ''">false</DryRun>
</PropertyGroup>

<Message
Expand Down Expand Up @@ -96,7 +97,7 @@
SymbolServerPath="%(SymbolServerTargets.Identity)"
ExpirationInDays="$(DotNetSymbolExpirationInDays)"
VerboseLogging="true"
DryRun="false"
DryRun="$(DryRun)"
ConvertPortablePdbsToWindowsPdbs="false"
PdbConversionTreatAsWarning=""
PublishSpecialClrFiles="$(PublishSpecialClrFiles)"
Expand Down
32 changes: 17 additions & 15 deletions src/Microsoft.DotNet.Build.Tasks.Feed/src/CreateAzureDevOpsFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public class CreateAzureDevOpsFeed : MSBuild.Task

public string AzureDevOpsFeedsApiVersion { get; set; } = "5.0-preview.1";

public static string AzureDevOpsOrg { get; set; } = "dnceng";

private readonly string AzureDevOpsFeedsBaseUrl = $"https://feeds.dev.azure.com/{AzureDevOpsOrg}/";
public string AzureDevOpsOrg { get; set; } = "dnceng";

/// <summary>
/// Number of characters from the commit SHA prefix that should be included in the feed name.
Expand Down Expand Up @@ -105,11 +103,12 @@ private async Task<bool> ExecuteAsync()
return false;
}

string azureDevOpsFeedsBaseUrl = $"https://feeds.dev.azure.com/{AzureDevOpsOrg}/";
do
{
using (HttpClient client = new HttpClient(new HttpClientHandler { CheckCertificateRevocationList = true })
{
BaseAddress = new Uri(AzureDevOpsFeedsBaseUrl)
BaseAddress = new Uri(azureDevOpsFeedsBaseUrl)
})
{
client.DefaultRequestHeaders.Add(
Expand All @@ -119,13 +118,12 @@ private async Task<bool> ExecuteAsync()
"Basic",
Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", AzureDevOpsPersonalAccessToken))));

AzureDevOpsArtifactFeed newFeed = new AzureDevOpsArtifactFeed(versionedFeedName);
AzureDevOpsArtifactFeed newFeed = new AzureDevOpsArtifactFeed(versionedFeedName, AzureDevOpsOrg);

string body = JsonConvert.SerializeObject(newFeed, _serializerSettings);

HttpRequestMessage postMessage = new HttpRequestMessage(HttpMethod.Post, $"{publicSegment}_apis/packaging/feeds");
postMessage.Content = new StringContent(body, Encoding.UTF8, "application/json");

HttpResponseMessage response = await client.SendAsync(postMessage);

if (response.StatusCode == HttpStatusCode.Created)
Expand Down Expand Up @@ -180,20 +178,24 @@ public Permission(string identityDescriptor, int role)

public class AzureDevOpsArtifactFeed
{
public AzureDevOpsArtifactFeed(string name)
public AzureDevOpsArtifactFeed(string name, string organization)
{
Name = name;
if (organization == "dnceng")
{
Permissions = new List<Permission>
{
// Mimic the permissions added to a feed when created in the browser
new Permission("Microsoft.TeamFoundation.ServiceIdentity;116cce53-b859-4624-9a95-934af41eccef:Build:b55de4ed-4b5a-4215-a8e4-0a0a5f71e7d8", 3), // Project Collection Build Service
new Permission("Microsoft.TeamFoundation.ServiceIdentity;116cce53-b859-4624-9a95-934af41eccef:Build:7ea9116e-9fac-403d-b258-b31fcf1bb293", 3), // internal Build Service
new Permission("Microsoft.TeamFoundation.Identity;S-1-9-1551374245-1349140002-2196814402-2899064621-3782482097-0-0-0-0-1", 4), // Feed administrators
new Permission("Microsoft.TeamFoundation.Identity;S-1-9-1551374245-1846651262-2896117056-2992157471-3474698899-1-2052915359-1158038602-2757432096-2854636005", 4) // Feed administrators and contributors
};
}
}

public string Name { get; set; }

public readonly List<Permission> Permissions = new List<Permission>
{
// Mimic the permissions added to a feed when created in the browser
new Permission("Microsoft.TeamFoundation.ServiceIdentity;116cce53-b859-4624-9a95-934af41eccef:Build:b55de4ed-4b5a-4215-a8e4-0a0a5f71e7d8", 3), // Project Collection Build Service
new Permission("Microsoft.TeamFoundation.ServiceIdentity;116cce53-b859-4624-9a95-934af41eccef:Build:7ea9116e-9fac-403d-b258-b31fcf1bb293", 3), // internal Build Service
new Permission("Microsoft.TeamFoundation.Identity;S-1-9-1551374245-1349140002-2196814402-2899064621-3782482097-0-0-0-0-1", 4), // Feed administrators
new Permission("Microsoft.TeamFoundation.Identity;S-1-9-1551374245-1846651262-2896117056-2992157471-3474698899-1-2052915359-1158038602-2757432096-2854636005", 4) // Feed administrators and contributors
};
public List<Permission> Permissions { get; private set; }
}
}