diff --git a/Tasks/AzureFunctionOnKubernetesV0/task.json b/Tasks/AzureFunctionOnKubernetesV0/task.json index f1eda6282b7f..b038210f0bfe 100644 --- a/Tasks/AzureFunctionOnKubernetesV0/task.json +++ b/Tasks/AzureFunctionOnKubernetesV0/task.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, - "Patch": 8 + "Minor": 161, + "Patch": 0 }, "demands": [], "groups": [ diff --git a/Tasks/AzureFunctionOnKubernetesV0/task.loc.json b/Tasks/AzureFunctionOnKubernetesV0/task.loc.json index 4a0d2c50c487..95badb63bec5 100644 --- a/Tasks/AzureFunctionOnKubernetesV0/task.loc.json +++ b/Tasks/AzureFunctionOnKubernetesV0/task.loc.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, - "Patch": 8 + "Minor": 161, + "Patch": 0 }, "demands": [], "groups": [ diff --git a/Tasks/Common/kubernetes-common-v2/image-metadata-helper.ts b/Tasks/Common/kubernetes-common-v2/image-metadata-helper.ts index dcf2d316750f..6a2ab947ca96 100644 --- a/Tasks/Common/kubernetes-common-v2/image-metadata-helper.ts +++ b/Tasks/Common/kubernetes-common-v2/image-metadata-helper.ts @@ -25,8 +25,8 @@ const manifestUrlLabel = "Manifest_Url"; export function getDeploymentMetadata(deploymentObject: any, allPods: any, deploymentStrategy: string, clusterInfo: any, manifestUrls: string[]): any { let imageIds: string[] = []; let containers = []; - let kind: string = deploymentObject.kind; try { + let kind: string = deploymentObject.kind; if (isPodEntity(kind)) { containers = deploymentObject.spec.containers; } @@ -75,7 +75,7 @@ export function getDeploymentMetadata(deploymentObject: any, allPods: any, deplo "Config": deploymentStrategy, "Address": getEnvironmentResourceAddress(clusterUrl), "Platform": getPlatform(), - "PipelineRunInfo" : getPipelineRunInfo() + "PipelineRunInfo": getPipelineRunInfo() }; return metadataDetails; @@ -241,7 +241,7 @@ export function extractManifestsFromHelmOutput(helmOutput: string): any { export function getManifestFileUrlsFromArgumentsInput(fileArgs: string): string[] { let manifestFileUrls: string[] = []; - const filePathMatch: string[] = fileArgs.split(matchPatternForFileArgument); + const filePathMatch: string[] = fileArgs ? fileArgs.split(matchPatternForFileArgument) : []; if (filePathMatch && filePathMatch.length > 0) { filePathMatch.forEach(manifestPath => { if (!!manifestPath) { @@ -392,10 +392,10 @@ function getPipelineRunInfo(): any { var deploymentPhaseIdentifier = tl.getVariable("Environment.DeploymentPhaseIdentifier") if (deploymentPhaseIdentifier) { return { - 'planId' : tl.getVariable("SYSTEM.PLANID"), - 'deploymentPhaseIdentifier' : tl.getVariable("Environment.DeploymentPhaseIdentifier"), - 'jobName' : tl.getVariable("SYSTEM.JOBNAME"), - 'hubName' : tl.getVariable("SYSTEM.HOSTTYPE") + 'planId': tl.getVariable("SYSTEM.PLANID"), + 'deploymentPhaseIdentifier': tl.getVariable("Environment.DeploymentPhaseIdentifier"), + 'jobName': tl.getVariable("SYSTEM.JOBNAME"), + 'hubName': tl.getVariable("SYSTEM.HOSTTYPE") }; } return null; diff --git a/Tasks/DockerV2/dockerpush.ts b/Tasks/DockerV2/dockerpush.ts index 62843dc27f08..c84060c5c36e 100644 --- a/Tasks/DockerV2/dockerpush.ts +++ b/Tasks/DockerV2/dockerpush.ts @@ -143,26 +143,21 @@ async function publishToImageMetadataStore(connection: ContainerConnection, imag imageFingerPrint = dockerCommandUtils.getImageFingerPrint(imageRootfsLayers, v1Name); } - const addPipelineData = tl.getBoolInput("addPipelineData"); - // Getting pipeline variables const build = "build"; const hostType = tl.getVariable("System.HostType").toLowerCase(); const runId = hostType === build ? parseInt(tl.getVariable("Build.BuildId")) : parseInt(tl.getVariable("Release.ReleaseId")); - const pipelineVersion = addPipelineData ? hostType === build ? tl.getVariable("Build.BuildNumber") : tl.getVariable("Release.ReleaseName") : ""; - const pipelineName = addPipelineData ? tl.getVariable("System.DefinitionName") : ""; - const pipelineId = addPipelineData ? tl.getVariable("System.DefinitionId") : ""; - const jobName = addPipelineData ? tl.getVariable("System.PhaseDisplayName") : ""; - const creator = addPipelineData ? dockerCommandUtils.getCreatorEmail() : ""; - const logsUri = addPipelineData ? dockerCommandUtils.getPipelineLogsUrl() : ""; - const artifactStorageSourceUri = addPipelineData ? dockerCommandUtils.getPipelineUrl() : ""; - - const repoUrl = tl.getVariable("Build.Repository.Uri"); - const contextUrl = addPipelineData && repoUrl ? repoUrl : ""; - - const commitId = tl.getVariable("Build.SourceVersion"); - const revisionId = addPipelineData && commitId ? commitId : ""; + const pipelineVersion = hostType === build ? tl.getVariable("Build.BuildNumber") : tl.getVariable("Release.ReleaseName"); + const pipelineName = tl.getVariable("System.DefinitionName"); + const pipelineId = tl.getVariable("System.DefinitionId"); + const jobName = tl.getVariable("System.PhaseDisplayName"); + const creator = dockerCommandUtils.getCreatorEmail(); + const logsUri = dockerCommandUtils.getPipelineLogsUrl(); + const artifactStorageSourceUri = dockerCommandUtils.getPipelineUrl(); + const contextUrl = tl.getVariable("Build.Repository.Uri") || ""; + const revisionId = tl.getVariable("Build.SourceVersion") || ""; + const addPipelineData = tl.getBoolInput("addPipelineData"); const labelArguments = pipelineUtils.getDefaultLabels(addPipelineData); const buildOptions = dockerCommandUtils.getBuildAndPushArguments(dockerFilePath, labelArguments, tags); diff --git a/Tasks/DockerV2/task.json b/Tasks/DockerV2/task.json index c62ae2e4566b..df4840b89d0f 100644 --- a/Tasks/DockerV2/task.json +++ b/Tasks/DockerV2/task.json @@ -14,7 +14,7 @@ "version": { "Major": 2, "Minor": 161, - "Patch": 2 + "Patch": 3 }, "demands": [], "releaseNotes": "Simplified the task YAML by:
 - Removing the Container registry type input
 - Removing complex inputs as they can be passed as arguments to the command.", diff --git a/Tasks/DockerV2/task.loc.json b/Tasks/DockerV2/task.loc.json index 913fc367a96f..bd58a6336c95 100644 --- a/Tasks/DockerV2/task.loc.json +++ b/Tasks/DockerV2/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 2, "Minor": 161, - "Patch": 2 + "Patch": 3 }, "demands": [], "releaseNotes": "ms-resource:loc.releaseNotes", diff --git a/Tasks/HelmDeployV0/src/helm.ts b/Tasks/HelmDeployV0/src/helm.ts index 9084f566a680..c461e3c19051 100644 --- a/Tasks/HelmDeployV0/src/helm.ts +++ b/Tasks/HelmDeployV0/src/helm.ts @@ -15,7 +15,6 @@ import fs = require('fs'); import * as commonCommandOptions from "./commoncommandoption"; tl.setResourcePath(path.join(__dirname, '..', 'task.json')); -const publishPipelineMetadata = tl.getVariable("PUBLISH_PIPELINE_METADATA"); function getKubeConfigFilePath(): string { var userdir = helmutil.getTaskTempDir(); @@ -124,26 +123,31 @@ function runHelm(helmCli: helmcli, command: string, kubectlCli: kubernetescli) { tl.debug('execResult: ' + JSON.stringify(execResult)); tl.setResult(tl.TaskResult.Failed, execResult.stderr); } - else if ((command === "install" || command === "upgrade") && publishPipelineMetadata && publishPipelineMetadata.toLowerCase() == "true") { - let output = execResult.stdout; - let manifests = extractManifestsFromHelmOutput(output); - if (manifests && manifests.length > 0) { - const manifestUrls = getManifestFileUrlsFromHelmOutput(output); - manifests.forEach(manifest => { - //Check if the manifest object contains a deployment entity - if (manifest.kind && isDeploymentEntity(manifest.kind)) { - try { - pushDeploymentDataToEvidenceStore(kubectlCli, manifest, manifestUrls).then((result) => { - tl.debug("DeploymentDetailsApiResponse: " + JSON.stringify(result)); - }, (error) => { - tl.warning("publishToImageMetadataStore failed with error: " + error); - }); + else if ((command === "install" || command === "upgrade")) { + try { + let output = execResult.stdout; + let manifests = extractManifestsFromHelmOutput(output); + if (manifests && manifests.length > 0) { + const manifestUrls = getManifestFileUrlsFromHelmOutput(output); + manifests.forEach(manifest => { + //Check if the manifest object contains a deployment entity + if (manifest.kind && isDeploymentEntity(manifest.kind)) { + try { + pushDeploymentDataToEvidenceStore(kubectlCli, manifest, manifestUrls).then((result) => { + tl.debug("DeploymentDetailsApiResponse: " + JSON.stringify(result)); + }, (error) => { + tl.warning("publishToImageMetadataStore failed with error: " + error); + }); + } + catch (e) { + tl.warning("publishToImageMetadataStore failed with error: " + e); + } } - catch (e) { - tl.warning("Capturing deployment metadata failed with error: " + e); - } - } - }); + }); + } + } + catch (e) { + tl.warning("Capturing deployment metadata failed with error: " + e); } } } diff --git a/Tasks/HelmDeployV0/task.json b/Tasks/HelmDeployV0/task.json index 5552d24eac5e..277ce0b32979 100644 --- a/Tasks/HelmDeployV0/task.json +++ b/Tasks/HelmDeployV0/task.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, + "Minor": 161, "Patch": 0 }, "demands": [], diff --git a/Tasks/HelmDeployV0/task.loc.json b/Tasks/HelmDeployV0/task.loc.json index 0154060df0d3..848d2fa6d5ad 100644 --- a/Tasks/HelmDeployV0/task.loc.json +++ b/Tasks/HelmDeployV0/task.loc.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, + "Minor": 161, "Patch": 0 }, "demands": [], diff --git a/Tasks/HelmInstallerV1/task.json b/Tasks/HelmInstallerV1/task.json index 305546ebb903..58ca0e16b906 100644 --- a/Tasks/HelmInstallerV1/task.json +++ b/Tasks/HelmInstallerV1/task.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 161, - "Patch": 0 + "Patch": 1 }, "preview": true, "demands": [], diff --git a/Tasks/HelmInstallerV1/task.loc.json b/Tasks/HelmInstallerV1/task.loc.json index 833653cba615..3a60d106d45f 100644 --- a/Tasks/HelmInstallerV1/task.loc.json +++ b/Tasks/HelmInstallerV1/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 161, - "Patch": 0 + "Patch": 1 }, "preview": true, "demands": [], diff --git a/Tasks/KubectlInstallerV0/task.json b/Tasks/KubectlInstallerV0/task.json index 9d8605c2bf34..728c091c1951 100644 --- a/Tasks/KubectlInstallerV0/task.json +++ b/Tasks/KubectlInstallerV0/task.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, + "Minor": 161, "Patch": 0 }, "demands": [], diff --git a/Tasks/KubectlInstallerV0/task.loc.json b/Tasks/KubectlInstallerV0/task.loc.json index 53743d0eeb17..e4e711b9f5f7 100644 --- a/Tasks/KubectlInstallerV0/task.loc.json +++ b/Tasks/KubectlInstallerV0/task.loc.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, + "Minor": 161, "Patch": 0 }, "demands": [], diff --git a/Tasks/KubernetesManifestV0/src/utils/DeploymentHelper.ts b/Tasks/KubernetesManifestV0/src/utils/DeploymentHelper.ts index c5fceb4cc85a..c4cf5c14df20 100644 --- a/Tasks/KubernetesManifestV0/src/utils/DeploymentHelper.ts +++ b/Tasks/KubernetesManifestV0/src/utils/DeploymentHelper.ts @@ -21,8 +21,6 @@ import { WebRequest, sendRequest } from 'utility-common-v2/restutilities'; import { deployPodCanary } from './PodCanaryDeploymentHelper'; import { deploySMICanary } from './SMICanaryDeploymentHelper'; -const publishPipelineMetadata = tl.getVariable("PUBLISH_PIPELINE_METADATA"); - export async function deploy(kubectl: Kubectl, manifestFilePaths: string[], deploymentStrategy: string) { // get manifest files @@ -48,12 +46,18 @@ export async function deploy(kubectl: Kubectl, manifestFilePaths: string[], depl }); // annotate resources - const allPods = JSON.parse((kubectl.getAllPods()).stdout); + let allPods: any; + try { + allPods = JSON.parse((kubectl.getAllPods()).stdout); + } + catch (e) { + tl.debug("Unable to parse pods; Error: "+ e); + } + annotateResources(deployedManifestFiles, kubectl, resourceTypes, allPods); - // Capture and push deployment metadata only if the variable 'PUBLISH_PIPELINE_METADATA' is set to true, - // and deployment strategy is not specified (because for Canary/SMI we do not replace actual deployment objects) - if (publishPipelineMetadata && publishPipelineMetadata.toLowerCase() == "true" && !isCanaryDeploymentStrategy(deploymentStrategy)) { + // Capture and push deployment metadata only if deployment strategy is not specified (because for Canary/SMI we do not replace actual deployment objects) + if (!isCanaryDeploymentStrategy(deploymentStrategy)) { try { const clusterInfo = kubectl.getClusterInfo().stdout; captureAndPushDeploymentMetadata(inputManifestFiles, allPods, deploymentStrategy, clusterInfo, manifestFilePaths); diff --git a/Tasks/KubernetesManifestV0/task.json b/Tasks/KubernetesManifestV0/task.json index 6f8a38394c0c..2d46439e84dd 100644 --- a/Tasks/KubernetesManifestV0/task.json +++ b/Tasks/KubernetesManifestV0/task.json @@ -13,8 +13,8 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, - "Patch": 7 + "Minor": 161, + "Patch": 0 }, "demands": [], "groups": [], diff --git a/Tasks/KubernetesManifestV0/task.loc.json b/Tasks/KubernetesManifestV0/task.loc.json index 6418e6ee6887..ddb7e4400108 100644 --- a/Tasks/KubernetesManifestV0/task.loc.json +++ b/Tasks/KubernetesManifestV0/task.loc.json @@ -13,8 +13,8 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 160, - "Patch": 7 + "Minor": 161, + "Patch": 0 }, "demands": [], "groups": [], diff --git a/Tasks/KubernetesV1/src/kubernetes.ts b/Tasks/KubernetesV1/src/kubernetes.ts index ef600ff79f2f..667d81232078 100644 --- a/Tasks/KubernetesV1/src/kubernetes.ts +++ b/Tasks/KubernetesV1/src/kubernetes.ts @@ -19,7 +19,6 @@ tl.cd(tl.getInput("cwd")); var registryType = tl.getInput("containerRegistryType", true); var command = tl.getInput("command", false); const environmentVariableMaximumSize = 32766; -const publishPipelineMetadata = tl.getVariable("PUBLISH_PIPELINE_METADATA"); var kubeconfigfilePath; if (command === "logout") { @@ -115,46 +114,65 @@ function executeKubectlCommand(clusterConnection: ClusterConnection, command: st tl.setVariable('KubectlOutput', resultString); } - const outputFormat: string = tl.getInput("outputFormat", false); - const isOutputFormatSpecified: boolean = outputFormat && (outputFormat.toLowerCase() === "json" || outputFormat.toLowerCase() === "yaml"); - // The deployment data is pushed to evidence store only for commands like 'apply' or 'create' which support Json and Yaml output format - if (publishPipelineMetadata && publishPipelineMetadata.toLowerCase() == "true" && isOutputFormatSpecified && isJsonOrYamlOutputFormatSupported(command)) { - const allPods = JSON.parse(getAllPods(clusterConnection).stdout); - const clusterInfo = getClusterInfo(clusterConnection).stdout; - - let fileArgs = ""; - const configFilePathArgs = getCommandConfigurationFile(); - if (configFilePathArgs.length > 0) { - fileArgs = configFilePathArgs.join(" "); - } - else { - fileArgs = tl.getInput("arguments", false); - } + try { + const outputFormat: string = tl.getInput("outputFormat", false); + const isOutputFormatSpecified: boolean = outputFormat && (outputFormat.toLowerCase() === "json" || outputFormat.toLowerCase() === "yaml"); + // The deployment data is pushed to evidence store only for commands like 'apply' or 'create' which support Json and Yaml output format + if (isOutputFormatSpecified && isJsonOrYamlOutputFormatSupported(command)) { + let podsOutputString: string = ""; + try { + podsOutputString = getAllPods(clusterConnection).stdout; + } + catch (e) { + tl.debug("Not pushing metadata to artifact metadata store as failed to retrieve container pods; Error: " + e); + return; + } - const manifestUrls = getManifestFileUrlsFromArgumentsInput(fileArgs); - // For each output, check if it contains a JSON object - result.forEach(res => { - let parsedObject: any; - if (IsJsonString(res)) { - parsedObject = JSON.parse(res); + if (!IsJsonString(podsOutputString)) { + tl.debug("Not pushing metadata to artifact metadata store as failed to retrieve container pods"); } else { - parsedObject = yaml.safeLoad(res); - } - // Check if the output contains a deployment - if (parsedObject.kind && isDeploymentEntity(parsedObject.kind)) { - try { - pushDeploymentDataToEvidenceStore(clusterConnection, parsedObject, allPods, clusterInfo, manifestUrls).then((result) => { - tl.debug("DeploymentDetailsApiResponse: " + JSON.stringify(result)); - }, (error) => { - tl.warning("publishToImageMetadataStore failed with error: " + error); - }); + const allPods = JSON.parse(podsOutputString); + const clusterInfo = getClusterInfo(clusterConnection).stdout; + + let fileArgs = ""; + const configFilePathArgs = getCommandConfigurationFile(); + if (configFilePathArgs.length > 0) { + fileArgs = configFilePathArgs.join(" "); } - catch (e) { - tl.warning("Capturing deployment metadata failed with error: " + e); + else { + fileArgs = tl.getInput("arguments", false); } + + const manifestUrls = getManifestFileUrlsFromArgumentsInput(fileArgs); + // For each output, check if it contains a JSON object + result.forEach(res => { + let parsedObject: any; + if (IsJsonString(res)) { + parsedObject = JSON.parse(res); + } + else { + parsedObject = yaml.safeLoad(res); + } + // Check if the output contains a deployment + if (parsedObject.kind && isDeploymentEntity(parsedObject.kind)) { + try { + pushDeploymentDataToEvidenceStore(clusterConnection, parsedObject, allPods, clusterInfo, manifestUrls).then((result) => { + tl.debug("DeploymentDetailsApiResponse: " + JSON.stringify(result)); + }, (error) => { + tl.warning("publishToImageMetadataStore failed with error: " + error); + }); + } + catch (e) { + tl.warning("pushDeploymentDataToEvidenceStore failed with error: " + e); + } + } + }); } - }); + } + } + catch (e) { + tl.warning("Capturing deployment metadata failed with error: " + e) } }); } diff --git a/make-options.json b/make-options.json index 0b245792b3c7..b537dd3be8cd 100644 --- a/make-options.json +++ b/make-options.json @@ -135,7 +135,6 @@ "PublishCodeCoverageResultsV1", "PublishPipelineArtifactV0", "PublishPipelineArtifactV1", - "PublishPipelineMetadataV0", "PublishSymbolsV2", "PublishTestResultsV1", "PublishTestResultsV2",