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

Removed publish metadata variable dependency #11817

Merged
merged 1 commit into from
Nov 21, 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
4 changes: 2 additions & 2 deletions Tasks/AzureFunctionOnKubernetesV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Patch": 8
"Minor": 161,
"Patch": 0
},
"demands": [],
"groups": [
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureFunctionOnKubernetesV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Patch": 8
"Minor": 161,
"Patch": 0
},
"demands": [],
"groups": [
Expand Down
14 changes: 7 additions & 7 deletions Tasks/Common/kubernetes-common-v2/image-metadata-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 10 additions & 15 deletions Tasks/DockerV2/dockerpush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Tasks/DockerV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 161,
"Patch": 2
"Patch": 3
},
"demands": [],
"releaseNotes": "Simplified the task YAML by:<br/>&nbsp;- Removing the Container registry type input<br/>&nbsp;- Removing complex inputs as they can be passed as arguments to the command.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DockerV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 161,
"Patch": 2
"Patch": 3
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
44 changes: 24 additions & 20 deletions Tasks/HelmDeployV0/src/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/HelmDeployV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Minor": 161,
"Patch": 0
},
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/HelmDeployV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Minor": 161,
"Patch": 0
},
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/HelmInstallerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 161,
"Patch": 0
"Patch": 1
},
"preview": true,
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/HelmInstallerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 161,
"Patch": 0
"Patch": 1
},
"preview": true,
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubectlInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Minor": 161,
"Patch": 0
},
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubectlInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Minor": 161,
"Patch": 0
},
"demands": [],
Expand Down
16 changes: 10 additions & 6 deletions Tasks/KubernetesManifestV0/src/utils/DeploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Tasks/KubernetesManifestV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Patch": 7
"Minor": 161,
"Patch": 0
},
"demands": [],
"groups": [],
Expand Down
4 changes: 2 additions & 2 deletions Tasks/KubernetesManifestV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 160,
"Patch": 7
"Minor": 161,
"Patch": 0
},
"demands": [],
"groups": [],
Expand Down
88 changes: 53 additions & 35 deletions Tasks/KubernetesV1/src/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
}
});
}
Expand Down
Loading