Skip to content

Commit 5c67209

Browse files
authored
Create short-lived tokens if Develocity injection is disabled (#552)
1 parent c2fd96f commit 5c67209

3 files changed

Lines changed: 17 additions & 27 deletions

File tree

src/main/java/hudson/plugins/gradle/injection/BuildScanEnvironmentContributor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public BuildScanEnvironmentContributor(ShortLivedTokenClient tokenClient) {
4343

4444
@Override
4545
public void buildEnvironmentFor(@Nonnull Run run, @Nonnull EnvVars envs, @Nonnull TaskListener listener) {
46-
if (InjectionConfig.get().isDisabled() || alreadyExecuted(run)) {
46+
if (alreadyExecuted(run)) {
4747
return;
4848
}
4949

src/main/resources/hudson/plugins/gradle/injection/InjectionConfig/config.jelly

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:l="/lib/layout" xmlns:c="/lib/credentials">
33
<f:section title="${%Develocity integration}">
4+
<f:entry title="Develocity Access Key credential ID" field="accessKeyCredentialId">
5+
<div class="alert alert-info" role="alert">
6+
<l:icon class="icon-help icon-sm" alt="${%Access key format help}"/>
7+
The access key must be in the <b><span>&lt;</span>server host name<span>&gt;</span>=<span>&lt;</span>access key<span>&gt;</span></b> format.
8+
For more details please refer to the <a class="alert-link" href="https://docs.gradle.com/enterprise/gradle-plugin/#manual_access_key_configuration" target="_blank">documentation</a>.
9+
</div>
10+
<c:select default="${instance.accessKeyCredentialId}"/>
11+
</f:entry>
12+
<f:entry title="${%Develocity short-lived access tokens expiry}" field="shortLivedTokenExpiry">
13+
<f:textbox checkMethod="post"/>
14+
</f:entry>
415
<f:optionalBlock field="enabled" title="${%Enable auto-injection}" inline="true">
516

617
<j:if test="${instance.showLegacyConfigurationWarning}">
@@ -33,17 +44,6 @@
3344
<f:entry field="enforceUrl">
3445
<f:checkbox title="${%Enforce Develocity server url}"/>
3546
</f:entry>
36-
<f:entry title="Develocity Access Key credential ID" field="accessKeyCredentialId">
37-
<div class="alert alert-info" role="alert">
38-
<l:icon class="icon-help icon-sm" alt="${%Access key format help}"/>
39-
The access key must be in the <b><span>&lt;</span>server host name<span>&gt;</span>=<span>&lt;</span>access key<span>&gt;</span></b> format.
40-
For more details please refer to the <a class="alert-link" href="https://docs.gradle.com/enterprise/gradle-plugin/#manual_access_key_configuration" target="_blank">documentation</a>.
41-
</div>
42-
<c:select default="${instance.accessKeyCredentialId}"/>
43-
</f:entry>
44-
<f:entry title="${%Develocity short-lived access tokens expiry}" field="shortLivedTokenExpiry">
45-
<f:textbox checkMethod="post"/>
46-
</f:entry>
4747
</f:section>
4848

4949
<f:section title="${%General settings}">

src/test/groovy/hudson/plugins/gradle/injection/BuildScanEnvironmentContributorTest.groovy

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,6 @@ class BuildScanEnvironmentContributorTest extends BaseJenkinsIntegrationTest {
5050
0 * run.addAction(_)
5151
}
5252

53-
def 'does nothing if Develocity injection is disabled'() {
54-
given:
55-
def config = InjectionConfig.get()
56-
config.setEnabled(false)
57-
config.save()
58-
59-
when:
60-
buildScanEnvironmentContributor.buildEnvironmentFor(run, new EnvVars(), TaskListener.NULL)
61-
62-
then:
63-
0 * run.addAction(_)
64-
}
65-
6653
def 'adds empty action if access key is invalid'() {
6754
given:
6855
def config = InjectionConfig.get()
@@ -112,12 +99,12 @@ class BuildScanEnvironmentContributorTest extends BaseJenkinsIntegrationTest {
11299
}
113100
}
114101

115-
def 'adds an action with the short lived token from one single access key'() {
102+
def 'adds an action with the short lived token from a single access key if Develocity injection is #enabled'(boolean enabled) {
116103
given:
117104
def accessKey = "localhost=secret"
118105
def accessKeyCredentialId = UUID.randomUUID().toString()
119106
def config = InjectionConfig.get()
120-
config.setEnabled(true)
107+
config.setEnabled(enabled)
121108
config.setServer('http://localhost')
122109
config.setAccessKeyCredentialId(accessKeyCredentialId)
123110
config.save()
@@ -141,6 +128,9 @@ class BuildScanEnvironmentContributorTest extends BaseJenkinsIntegrationTest {
141128
paramEquals(parameters[1], 'DEVELOCITY_ACCESS_KEY', 'localhost=xyz')
142129
}
143130
}
131+
132+
where:
133+
enabled << [true, false]
144134
}
145135

146136
def 'adds an action with the short lived token with multiple keys and enforce url is true'() {

0 commit comments

Comments
 (0)