Skip to content

Commit

Permalink
Removed the publish metadata pipeline variable
Browse files Browse the repository at this point in the history
  • Loading branch information
nidabas committed Nov 19, 2019
1 parent f0bf16d commit 4dc5b9a
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 61 deletions.
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
3 changes: 1 addition & 2 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,7 +123,7 @@ 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") {
else if ((command === "install" || command === "upgrade")) {
let output = execResult.stdout;
let manifests = extractManifestsFromHelmOutput(output);
if (manifests && manifests.length > 0) {
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
7 changes: 2 additions & 5 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 Down Expand Up @@ -51,9 +49,8 @@ export async function deploy(kubectl: Kubectl, manifestFilePaths: string[], depl
const allPods = JSON.parse((kubectl.getAllPods()).stdout);
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
73 changes: 43 additions & 30 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 @@ -118,43 +117,57 @@ function executeKubectlCommand(clusterConnection: ClusterConnection, command: st
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(" ");
if (isOutputFormatSpecified && isJsonOrYamlOutputFormatSupported(command)) {
let podsOutputString: string = "";
try {
podsOutputString = getAllPods(clusterConnection).stdout;
}
else {
fileArgs = tl.getInput("arguments", false);
catch (e) {
tl.debug("Not pushing metadata to artifact metadata store as failed to retrieve container pods; Error: " + e);
return;
}

if (!IsJsonString(podsOutputString)) {
tl.debug("Not pushing metadata to artifact metadata store as failed to retrieve container pods");
}
else {
const allPods = JSON.parse(podsOutputString);
const clusterInfo = getClusterInfo(clusterConnection).stdout;

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);
let fileArgs = "";
const configFilePathArgs = getCommandConfigurationFile();
if (configFilePathArgs.length > 0) {
fileArgs = configFilePathArgs.join(" ");
}
else {
parsedObject = yaml.safeLoad(res);
fileArgs = tl.getInput("arguments", false);
}
// 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 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);
}
catch (e) {
tl.warning("Capturing deployment metadata failed with error: " + e);
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("Capturing deployment metadata failed with error: " + e);
}
}
});
}
}
});
}
Expand Down
1 change: 0 additions & 1 deletion make-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
"PublishCodeCoverageResultsV1",
"PublishPipelineArtifactV0",
"PublishPipelineArtifactV1",
"PublishPipelineMetadataV0",
"PublishSymbolsV2",
"PublishTestResultsV1",
"PublishTestResultsV2",
Expand Down

0 comments on commit 4dc5b9a

Please sign in to comment.