Skip to content

Commit 5109219

Browse files
authored
Merge pull request #2141 from microsoft/gavinbarron/cfs-package-feeds
Route Gradle dependency resolution through the CFS central package feed
2 parents dfab645 + 3a21323 commit 5109219

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

.azure-pipelines/ci-build.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,34 @@ extends:
7272
Copy-Item $(downloadLocalProperties.secureFilePath) local.properties -Verbose
7373
displayName: Copy secring and 'local.properties'
7474
75-
- script: ./gradlew --no-daemon publishToMavenLocal -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
75+
- task: MavenAuthenticate@0
76+
displayName: Authenticate to Azure Artifacts feed (PAT-less)
77+
inputs:
78+
artifactsFeeds: 'GraphDeveloperExperiences_Public'
79+
80+
- script: ./gradlew --no-daemon --init-script .azure-pipelines/network-isolation-feed.init.gradle publishToMavenLocal -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
7681
displayName: Publish to local Maven for verification
7782
condition: contains(variables['build.sourceBranch'], 'refs/tags/v')
83+
env:
84+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
7885

79-
- script: ./gradlew --no-daemon publishToMavenLocal -PmavenCentralPublishingEnabled=true
86+
- script: ./gradlew --no-daemon --init-script .azure-pipelines/network-isolation-feed.init.gradle publishToMavenLocal -PmavenCentralPublishingEnabled=true
8087
displayName: Publish to local Maven for verification
8188
condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
89+
env:
90+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
8291

83-
- script: ./gradlew --no-daemon publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
92+
- script: ./gradlew --no-daemon --init-script .azure-pipelines/network-isolation-feed.init.gradle publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true -PmavenCentralSnapshotArtifactSuffix=""
8493
displayName: Publish to local Maven ADO for ESRP
8594
condition: contains(variables['build.sourceBranch'], 'refs/tags/v')
95+
env:
96+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
8697

87-
- script: ./gradlew --no-daemon publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true
98+
- script: ./gradlew --no-daemon --init-script .azure-pipelines/network-isolation-feed.init.gradle publishMavenPublicationToADORepository -PmavenCentralPublishingEnabled=true
8899
displayName: Publish to local Maven ADO for ESRP
89100
condition: not(contains(variables['build.sourceBranch'], 'refs/tags/v'))
101+
env:
102+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
90103

91104
- pwsh: |
92105
$contents = Get-Content gradle.properties -Raw
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Network-isolated CI (CFS): route ALL Gradle dependency and plugin resolution through the
2+
// authenticated Azure Artifacts feed instead of public repositories (Maven Central / Gradle Plugin
3+
// Portal). This feed is an upstream-mirroring feed, so it must have Maven Central configured as an
4+
// upstream source (and the Gradle Plugin Portal upstream, for plugin resolution).
5+
//
6+
// Authentication uses the pipeline OAuth token exposed as SYSTEM_ACCESSTOKEN; the Project Collection
7+
// Build Service identity must have at least Reader access to the feed. This init script is applied via
8+
// `--init-script` from .azure-pipelines/ci-build.yml and is paired with the MavenAuthenticate@0 task.
9+
import org.gradle.api.artifacts.dsl.RepositoryHandler
10+
import org.gradle.api.credentials.HttpHeaderCredentials
11+
import org.gradle.authentication.http.HttpHeaderAuthentication
12+
13+
final String FEED_URL = 'https://microsoftgraph.pkgs.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/GraphDeveloperExperiences_Public/maven/v1'
14+
final String ACCESS_TOKEN = System.getenv('SYSTEM_ACCESSTOKEN')
15+
16+
Closure applyFeed = { RepositoryHandler repositories ->
17+
repositories.clear()
18+
repositories.maven { repo ->
19+
repo.url = FEED_URL
20+
repo.credentials(HttpHeaderCredentials) { creds ->
21+
creds.name = 'Authorization'
22+
creds.value = "Bearer ${ACCESS_TOKEN}"
23+
}
24+
repo.authentication { container -> container.create('header', HttpHeaderAuthentication) }
25+
}
26+
}
27+
28+
// Redirect plugin resolution (settings pluginManagement) to the feed.
29+
settingsEvaluated { settings ->
30+
applyFeed(settings.pluginManagement.repositories)
31+
}
32+
33+
// Redirect buildscript classpath + project dependency resolution for every project to the feed.
34+
allprojects { project ->
35+
applyFeed(project.buildscript.repositories)
36+
applyFeed(project.repositories)
37+
}

0 commit comments

Comments
 (0)