Skip to content

Commit 8a62ee9

Browse files
authored
Prevent empty Jenkins URL being sent to Azure (#310)
1 parent bb935f9 commit 8a62ee9

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,14 @@ def myCloud = new AzureVMCloudBuilder()
228228
Jenkins.getInstance().clouds.add(myCloud)
229229
```
230230
This sample only contains a few arguments of builder, please find all the arguments in folder [builders](src/main/java/com/microsoft/azure/vmagent/builders).
231+
232+
## Troubleshooting
233+
234+
### Deployment validation failure
235+
236+
If you can't tell from validation why a deployment does not work you can enable additional logging.
237+
238+
The plugin creates a Jenkins logger called `Azure VM Agent (Auto)`, update that to `FINE` level and re-run the agent provisioning.
239+
The ARM template which is used to deploy resources will now show up.
240+
241+
More information on Jenkins logs can be found in the Jenkins documentation for [Viewing logs](https://www.jenkins.io/doc/book/system-administration/viewing-logs/).

src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
import java.util.logging.Logger;
8080
import java.util.stream.Collectors;
8181

82+
import static hudson.Util.fixEmpty;
83+
import static java.util.Objects.requireNonNull;
84+
8285
/**
8386
* Business delegate class which handles calls to Azure management service SDK.
8487
*
@@ -497,7 +500,11 @@ public AzureVMDeploymentInfo createDeployment(
497500
// If using the custom script extension (vs. SSH) to startup the powershell scripts,
498501
// add variables for that and upload the init script to the storage account
499502
if (useCustomScriptExtension) {
500-
putVariable(tmp, "jenkinsServerURL", Jenkins.get().getRootUrl());
503+
String rootUrl = fixEmpty(Jenkins.get().getRootUrl());
504+
if (rootUrl == null) {
505+
throw AzureCloudException.create("Jenkins URL must be set");
506+
}
507+
putVariable(tmp, "jenkinsServerURL", rootUrl);
501508
// Calculate the client secrets. The secrets are based off the machine name,
502509
ArrayNode clientSecretsNode = ((ObjectNode) tmp.get("variables")).putArray("clientSecrets");
503510
for (int i = 0; i < numberOfAgents; i++) {
@@ -584,9 +591,11 @@ public AzureVMDeploymentInfo createDeployment(
584591
cloudName, template.getResourceGroupName(), deploymentName, scriptUri);
585592
// Create the deployment
586593

594+
String templateJson = tmp.toString();
595+
LOGGER.log(Level.FINE, templateJson);
587596
azureClient.deployments().define(deploymentName)
588597
.withExistingResourceGroup(template.getResourceGroupName())
589-
.withTemplate(tmp.toString())
598+
.withTemplate(templateJson)
590599
.withParameters(parameters.toString())
591600
.withMode(DeploymentMode.INCREMENTAL)
592601
.beginCreate();

0 commit comments

Comments
 (0)