Skip to content

Commit 8ff6f9f

Browse files
committed
Authenticate when pulling io.spring.docresources:spring-doc-resources from Arifactory repo.spring.io/release repository.
1 parent 54a1e94 commit 8ff6f9f

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

Jenkinsfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ pipeline {
6464
script {
6565
docker.image(p['docker.container.image.java.main']).inside(p['docker.container.inside.env.basic']) {
6666
withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
67-
try {
68-
sh "ci/deployDocs.sh"
69-
}
70-
catch (e) {
71-
currentBuild.result = "FAILED: deploy docs"
72-
throw e
67+
withCredentials([usernamePassword(credentialsId: p['artifactory.credentials'], usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
68+
try {
69+
sh "ci/deployDocs.sh"
70+
}
71+
catch (e) {
72+
currentBuild.result = "FAILED: deploy docs"
73+
throw e
74+
}
7375
}
7476
}
7577
}

buildSrc/src/main/java/io/spring/gradle/convention/AsciidoctorConventionPlugin.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,41 @@ private void createDefaultAsciidoctorRepository(Project project) {
121121

122122
if (repositories.isEmpty()) {
123123
repositories.mavenCentral();
124-
repositories.maven(repo -> repo.setUrl(URI.create("https://repo.spring.io/release")));
124+
repositories.maven(repo -> {
125+
repo.credentials(passwordCredentials -> {
126+
passwordCredentials.setUsername(resolveArtifactoryUsername(project));
127+
passwordCredentials.setPassword(resolveArtifactoryPassword(project));
128+
});
129+
repo.setUrl(URI.create("https://repo.spring.io/release"));
130+
});
125131
}
126132
});
127133
}
128134

135+
private boolean isCredentialSet(Object target) {
136+
return target != null && !String.valueOf(target).trim().isEmpty();
137+
}
138+
139+
private String resolveArtifactoryPassword(Project project) {
140+
141+
Object artifactoryPassword = project.getProperties().get("artifactoryPassword");
142+
143+
artifactoryPassword = isCredentialSet(artifactoryPassword) ? artifactoryPassword
144+
: System.getenv().get("ARTIFACTORY_PASSWORD");
145+
146+
return String.valueOf(artifactoryPassword);
147+
}
148+
149+
private String resolveArtifactoryUsername(Project project) {
150+
151+
Object artifactoryUsername = project.getProperties().get("artifactoryUsername");
152+
153+
artifactoryUsername = isCredentialSet(artifactoryUsername) ? artifactoryUsername
154+
: System.getenv().get("ARTIFACTORY_USERNAME");
155+
156+
return String.valueOf(artifactoryUsername);
157+
}
158+
129159
/**
130160
* Requests the base Spring Documentation Resources from {@literal https://repo.spring.io/release} and uses it
131161
* to format and render documentation.

0 commit comments

Comments
 (0)