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

Changes to kudu logs pushed in deploy task #10790

Merged
merged 15 commits into from
Jul 16, 2019
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
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppContainerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 155,
"Minor": 156,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppContainerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 155,
"Minor": 156,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { AzureAppServiceUtility } from 'azurermdeploycommon/operations/AzureAppS
import tl = require('azure-pipelines-task-lib/task');
import * as ParameterParser from 'azurermdeploycommon/operations/ParameterParserUtility'
import { addReleaseAnnotation } from 'azurermdeploycommon/operations/ReleaseAnnotationUtility';
import { PackageUtility } from 'azurermdeploycommon/webdeployment-common/packageUtility';
import { AzureDeployPackageArtifactAlias } from 'azurermdeploycommon/Constants';

export class AzureRmWebAppDeploymentProvider implements IWebAppDeploymentProvider {
protected taskParams:TaskParameters;
Expand All @@ -19,6 +21,8 @@ export class AzureRmWebAppDeploymentProvider implements IWebAppDeploymentProvide

constructor(taskParams: TaskParameters) {
this.taskParams = taskParams;
let packageArtifactAlias = PackageUtility.getArtifactAlias(this.taskParams.Package.getPath());
tl.setVariable(AzureDeployPackageArtifactAlias, packageArtifactAlias);
}

public async PreDeploymentStep() {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureMysqlDeploymentV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 28
"Patch": 29
},
"demands": [],
"minimumAgentVersion": "1.100.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureMysqlDeploymentV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 28
"Patch": 29
},
"demands": [],
"minimumAgentVersion": "1.100.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { AzureAppServiceUtility } from '../operations/AzureAppServiceUtility';
import tl = require('azure-pipelines-task-lib/task');
import * as ParameterParser from 'webdeployment-common-v2/ParameterParserUtility';
import { addReleaseAnnotation } from '../operations/ReleaseAnnotationUtility';
import { PackageUtility } from 'webdeployment-common-v2/packageUtility';
import { AzureDeployPackageArtifactAlias } from '../operations/Constants';

export class AzureRmWebAppDeploymentProvider implements IWebAppDeploymentProvider{
protected taskParams:TaskParameters;
Expand All @@ -23,6 +25,8 @@ export class AzureRmWebAppDeploymentProvider implements IWebAppDeploymentProvide

constructor(taskParams: TaskParameters) {
this.taskParams = taskParams;
let packageArtifactAlias = PackageUtility.getArtifactAlias(this.taskParams.Package.getPath());
tl.setVariable(AzureDeployPackageArtifactAlias, packageArtifactAlias);
}

public async PreDeploymentStep() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,57 @@ import webClient = require('azure-arm-rest-v2/webClient');
var parseString = require('xml2js').parseString;
import Q = require('q');
import { Kudu } from 'azure-arm-rest-v2/azure-arm-app-service-kudu';
import { AzureDeployPackageArtifactAlias } from './Constants';

export class AzureAppServiceUtility {
private _appService: AzureAppService;
constructor(appService: AzureAppService) {
this._appService = appService;
}

public async updateScmTypeAndConfigurationDetails() : Promise<void>{
try {
public async updateScmTypeAndConfigurationDetails(): Promise<void> {
try {
var configDetails = await this._appService.getConfiguration();
var scmType: string = configDetails.properties.scmType;
let shouldUpdateMetadata = false;
if (scmType && scmType.toLowerCase() === "none") {
configDetails.properties.scmType = 'VSTSRM';
tl.debug('updating SCM Type to VSTS-RM');
await this._appService.updateConfiguration(configDetails);
tl.debug('updated SCM Type to VSTS-RM');
tl.debug('Updating metadata with latest release details');
await this._appService.patchMetadata(this._getNewMetadata());
tl.debug('Updated metadata with latest release details');
console.log(tl.loc("SuccessfullyUpdatedAzureRMWebAppConfigDetails"));
shouldUpdateMetadata = true;
}
else if (scmType && scmType.toLowerCase() == "vstsrm") {
tl.debug("SCM Type is VSTSRM");
shouldUpdateMetadata = true;
}
else {
tl.debug(`Skipped updating the SCM value. Value: ${scmType}`);
}

if (shouldUpdateMetadata) {
tl.debug('Updating metadata with latest pipeline details');
let newMetadataProperties = this._getNewMetadata();
let siteMetadata = await this._appService.getMetadata();
let skipUpdate = true;
for (let property in newMetadataProperties) {
if (siteMetadata.properties[property] !== newMetadataProperties[property]) {
siteMetadata.properties[property] = newMetadataProperties[property];
skipUpdate = false;
}
}

if (!skipUpdate) {
await this._appService.patchMetadata(siteMetadata.properties);
tl.debug('Updated metadata with latest pipeline details');
console.log(tl.loc("SuccessfullyUpdatedAzureRMWebAppConfigDetails"));
}
else {
tl.debug("No changes in metadata properties, skipping update.");
}
}
}
catch(error) {
catch (error) {
tl.warning(tl.loc("FailedToUpdateAzureRMWebAppConfigDetails", error));
}
}
Expand Down Expand Up @@ -253,17 +278,43 @@ export class AzureAppServiceUtility {

if(!!releaseDefinitionId) {
// Task is running in Release
let buildDefintionId = tl.getVariable("build.definitionId");
var artifactAlias = tl.getVariable(AzureDeployPackageArtifactAlias);
tl.debug("Artifact Source Alias is: "+ artifactAlias);

let buildDefinitionUrl = "";
let buildDefintionId = "";

if (artifactAlias) {
let artifactType = tl.getVariable(`release.artifacts.${artifactAlias}.type`);
// Get build definition info only when artifact type is build.
if (artifactType && artifactType.toLowerCase() == "build") {

buildDefintionId = tl.getVariable("build.definitionId");
let buildProjectId = tl.getVariable("build.projectId") || projectId;
let artifactBuildDefinitionId = tl.getVariable("release.artifacts." + artifactAlias + ".definitionId");
let artifactBuildProjectId = tl.getVariable("release.artifacts." + artifactAlias + ".projectId");

if (artifactBuildDefinitionId && artifactBuildProjectId) {
buildDefintionId = artifactBuildDefinitionId;
buildProjectId = artifactBuildProjectId;
}

buildDefinitionUrl = collectionUri + buildProjectId + "/_build?_a=simple-process&definitionId=" + buildDefintionId;
}
}

newProperties["VSTSRM_BuildDefinitionId"] = buildDefintionId;
newProperties["VSTSRM_ReleaseDefinitionId"] = releaseDefinitionId;
newProperties["VSTSRM_BuildDefinitionWebAccessUrl"] = collectionUri + projectId + "/_build?_a=simple-process&definitionId=" + buildDefintionId;
newProperties["VSTSRM_BuildDefinitionWebAccessUrl"] = buildDefinitionUrl;
newProperties["VSTSRM_ConfiguredCDEndPoint"] = collectionUri + projectId + "/_apps/hub/ms.vss-releaseManagement-web.hub-explorer?definitionId=" + releaseDefinitionId;
}
else {
// Task is running in Build
let buildDefintionId = tl.getVariable("system.definitionId");
newProperties["VSTSRM_BuildDefinitionId"] = buildDefintionId;
newProperties["VSTSRM_ConfiguredCDEndPoint"] = collectionUri + projectId + "/_build?_a=simple-process&definitionId=" + buildDefintionId;
let buildDefinitionUrl = collectionUri + projectId + "/_build?_a=simple-process&definitionId=" + buildDefintionId;
newProperties["VSTSRM_BuildDefinitionWebAccessUrl"] = buildDefinitionUrl
newProperties["VSTSRM_ConfiguredCDEndPoint"] = buildDefinitionUrl;
}

return newProperties;
Expand Down
4 changes: 3 additions & 1 deletion Tasks/AzureRmWebAppDeploymentV4/operations/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export const PublishProfileXml = {
DeployIisAppPath: "DeployIisAppPath",
MSDeploy: "MSDeploy",
UserName: "UserName"
}
}

export const AzureDeployPackageArtifactAlias = "Azure_App_Service_Deploy_PackageArtifactAlias";
73 changes: 48 additions & 25 deletions Tasks/AzureRmWebAppDeploymentV4/operations/KuduServiceUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Kudu } from 'azure-arm-rest-v2/azure-arm-app-service-kudu';
import { KUDU_DEPLOYMENT_CONSTANTS } from 'azure-arm-rest-v2/constants';
import webClient = require('azure-arm-rest-v2/webClient');
import { TaskParameters, DeploymentType } from './TaskParameters';
import { AzureDeployPackageArtifactAlias } from './Constants';
var deployUtility = require('webdeployment-common-v2/utility.js');
var zipUtility = require('webdeployment-common-v2/ziputility.js');
const physicalRootPath: string = '/site/wwwroot';
Expand Down Expand Up @@ -425,35 +426,54 @@ export class KuduServiceUtility {

private _getUpdateHistoryRequest(isDeploymentSuccess: boolean, deploymentID?: string, customMessage?: any): any {

var artifactAlias = tl.getVariable(AzureDeployPackageArtifactAlias);
var status = isDeploymentSuccess ? KUDU_DEPLOYMENT_CONSTANTS.SUCCESS : KUDU_DEPLOYMENT_CONSTANTS.FAILED;
var author = tl.getVariable('build.sourceVersionAuthor') || tl.getVariable('build.requestedfor') ||
tl.getVariable('release.requestedfor') || tl.getVariable('agent.name')

var buildUrl = tl.getVariable('build.buildUri');
var releaseUrl = tl.getVariable('release.releaseUri');

var buildId = tl.getVariable('build.buildId');
var releaseId = tl.getVariable('release.releaseId');

var buildNumber = tl.getVariable('build.buildNumber');
var releaseName = tl.getVariable('release.releaseName');

var collectionUrl = tl.getVariable('system.TeamFoundationCollectionUri');
var teamProject = tl.getVariable('system.teamProjectId');

var commitId = tl.getVariable('build.sourceVersion');
var repoName = tl.getVariable('build.repository.name');
var repoProvider = tl.getVariable('build.repository.provider');

var buildOrReleaseUrl = "" ;
deploymentID = !!deploymentID ? deploymentID : this.getDeploymentID();

if(releaseUrl !== undefined) {
buildOrReleaseUrl = collectionUrl + teamProject + "/_apps/hub/ms.vss-releaseManagement-web.hub-explorer?releaseId=" + releaseId + "&_a=release-summary";
let buildId = '', buildNumber = '', buildProject = '', commitId = '', repoProvider = '', repoName = '', branch = '', repositoryUrl = '', author = '';

if (releaseId && artifactAlias) {
// Task is running in release determine build information of selected artifact using artifactAlias
author = tl.getVariable('release.requestedfor') || tl.getVariable('agent.name');
tl.debug(`Artifact Source Alias is: ${artifactAlias}`);

commitId = tl.getVariable(`release.artifacts.${artifactAlias}.sourceVersion`);
repoProvider = tl.getVariable(`release.artifacts.${artifactAlias}.repository.provider`);
repoName = tl.getVariable(`release.artifacts.${artifactAlias}.repository.name`);
branch = tl.getVariable(`release.artifacts.${artifactAlias}.sourcebranchname`) || tl.getVariable(`release.artifacts.${artifactAlias}.sourcebranch`);

let artifactType = tl.getVariable(`release.artifacts.${artifactAlias}.type`);
if (artifactType && artifactType.toLowerCase() == "tfvc") {
repositoryUrl = `${collectionUrl}${buildProject}/_versionControl`;
repoProvider = "tfsversioncontrol";
}
else if(artifactType && artifactType.toLowerCase() == "build") {
buildId = tl.getVariable(`release.artifacts.${artifactAlias}.buildId`);
buildNumber = tl.getVariable(`release.artifacts.${artifactAlias}.buildNumber`);
buildProject = tl.getVariable(`release.artifacts.${artifactAlias}.projectId`);
}
else {
repositoryUrl = tl.getVariable(`release.artifacts.${artifactAlias}.repository.uri`);
}
}
else if(buildUrl !== undefined) {
buildOrReleaseUrl = collectionUrl + teamProject + "/_build?buildId=" + buildId + "&_a=summary";
else {
// Task is running in build OR artifact alias not found so use primary artifact variables
sachinma marked this conversation as resolved.
Show resolved Hide resolved
author = tl.getVariable('build.requestedfor') || tl.getVariable('agent.name');

buildId = tl.getVariable('build.buildId');
buildNumber = tl.getVariable('build.buildNumber');
buildProject = teamProject;

commitId = tl.getVariable('build.sourceVersion');
repoName = tl.getVariable('build.repository.name');
repoProvider = tl.getVariable('build.repository.provider');
repositoryUrl = tl.getVariable("build.repository.uri") || "";
branch = tl.getVariable("build.sourcebranchname") || tl.getVariable("build.sourcebranch");
}

deploymentID = !!deploymentID ? deploymentID : this.getDeploymentID();

var message = {
type : "deployment",
Expand All @@ -465,7 +485,11 @@ export class KuduServiceUtility {
repoProvider : repoProvider,
repoName : repoName,
collectionUrl : collectionUrl,
teamProject : teamProject
teamProject : teamProject,
buildProjectUrl: buildProject ? collectionUrl + buildProject : "",
repositoryUrl: repositoryUrl,
branch: branch,
teamProjectName: tl.getVariable("system.teamproject")
};

if(!!customMessage) {
Expand All @@ -487,8 +511,7 @@ export class KuduServiceUtility {
status : status,
message : JSON.stringify(message),
author : author,
deployer : 'VSTS',
details : buildOrReleaseUrl
deployer : 'VSTS'
sachinma marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 4,
"Minor": 155,
"Minor": 156,
"Patch": 0
},
"releaseNotes": "What's new in version 4.*<br />Supports Zip Deploy, Run From Package, War Deploy [Details here](https://aka.ms/appServiceDeploymentMethods)<br />Supports App Service Environments<br />Improved UI for discovering different App service types supported by the task<br/>Run From Package is the preferred deployment method, which makes files in wwwroot folder read-only<br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more information.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 4,
"Minor": 155,
"Minor": 156,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppContainerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 20
"Patch": 21
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppContainerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 20
"Patch": 21
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { AzureAppServiceUtility } from 'azurermdeploycommon/operations/AzureAppS
import tl = require('azure-pipelines-task-lib/task');
import * as ParameterParser from 'azurermdeploycommon/operations/ParameterParserUtility'
import { addReleaseAnnotation } from 'azurermdeploycommon/operations/ReleaseAnnotationUtility';
import { PackageUtility } from 'azurermdeploycommon/webdeployment-common/packageUtility';
import { AzureDeployPackageArtifactAlias } from 'azurermdeploycommon/Constants';

export class AzureRmWebAppDeploymentProvider implements IWebAppDeploymentProvider {
protected taskParams:TaskParameters;
Expand All @@ -19,6 +21,8 @@ export class AzureRmWebAppDeploymentProvider implements IWebAppDeploymentProvide

constructor(taskParams: TaskParameters) {
this.taskParams = taskParams;
let packageArtifactAlias = PackageUtility.getArtifactAlias(this.taskParams.Package.getPath());
tl.setVariable(AzureDeployPackageArtifactAlias, packageArtifactAlias);
}

public async PreDeploymentStep() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class BuiltInLinuxWebAppDeploymentProvider extends AzureRmWebAppDeploymen
case PackageType.war:
tl.debug("Initiated deployment via kudu service for webapp war package : "+ this.taskParams.Package.getPath());
let warName = webCommonUtility.getFileNameFromPath(this.taskParams.Package.getPath(), ".war");
this.zipDeploymentID = await this.kuduServiceUtility.deployUsingWarDeploy(this.taskParams.Package.getPath(),
this.zipDeploymentID = await this.kuduServiceUtility.deployUsingWarDeploy(this.taskParams.Package.getPath(),
{ slotName: this.appService.getSlot() }, warName);
break;

Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 19
"Patch": 20
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 19
"Patch": 20
},
"minimumAgentVersion": "2.104.1",
"groups": [
Expand Down
1 change: 1 addition & 0 deletions Tasks/Common/AzureRmDeploy-common/Constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const AzureDeployPackageArtifactAlias = "Azure_App_Service_Deploy_PackageArtifactAlias";
Loading