You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-09-16 09:26:22 +02:00
CommitHash for deployment details in influx (#3028)
* Adds commitHash to influxdata for cloudFoundryDeploy
This commit is contained in:
@@ -182,6 +182,7 @@ func prepareInflux(success bool, config *cloudFoundryDeployOptions, influxData *
|
||||
|
||||
// n/a (literally) is also reported in groovy
|
||||
influxData.deployment_data.fields.artifactURL = "n/a"
|
||||
influxData.deployment_data.fields.commitHash = config.CommitHash
|
||||
|
||||
influxData.deployment_data.fields.deployTime = strings.ToUpper(_now().Format("Jan 02 2006 15:04:05"))
|
||||
|
||||
|
@@ -20,6 +20,7 @@ type cloudFoundryDeployOptions struct {
|
||||
APIEndpoint string `json:"apiEndpoint,omitempty"`
|
||||
AppName string `json:"appName,omitempty"`
|
||||
ArtifactVersion string `json:"artifactVersion,omitempty"`
|
||||
CommitHash string `json:"commitHash,omitempty"`
|
||||
CfHome string `json:"cfHome,omitempty"`
|
||||
CfNativeDeployParameters string `json:"cfNativeDeployParameters,omitempty"`
|
||||
CfPluginHome string `json:"cfPluginHome,omitempty"`
|
||||
@@ -51,6 +52,7 @@ type cloudFoundryDeployInflux struct {
|
||||
fields struct {
|
||||
artifactURL string
|
||||
deployTime string
|
||||
commitHash string
|
||||
jobTrigger string
|
||||
}
|
||||
tags struct {
|
||||
@@ -73,6 +75,7 @@ func (i *cloudFoundryDeployInflux) persist(path, resourceName string) {
|
||||
}{
|
||||
{valType: config.InfluxField, measurement: "deployment_data", name: "artifactUrl", value: i.deployment_data.fields.artifactURL},
|
||||
{valType: config.InfluxField, measurement: "deployment_data", name: "deployTime", value: i.deployment_data.fields.deployTime},
|
||||
{valType: config.InfluxField, measurement: "deployment_data", name: "commitHash", value: i.deployment_data.fields.commitHash},
|
||||
{valType: config.InfluxField, measurement: "deployment_data", name: "jobTrigger", value: i.deployment_data.fields.jobTrigger},
|
||||
{valType: config.InfluxTag, measurement: "deployment_data", name: "artifactVersion", value: i.deployment_data.tags.artifactVersion},
|
||||
{valType: config.InfluxTag, measurement: "deployment_data", name: "deployUser", value: i.deployment_data.tags.deployUser},
|
||||
@@ -179,6 +182,7 @@ func addCloudFoundryDeployFlags(cmd *cobra.Command, stepConfig *cloudFoundryDepl
|
||||
cmd.Flags().StringVar(&stepConfig.APIEndpoint, "apiEndpoint", `https://api.cf.eu10.hana.ondemand.com`, "Cloud Foundry API endpoint")
|
||||
cmd.Flags().StringVar(&stepConfig.AppName, "appName", os.Getenv("PIPER_appName"), "Defines the name of the application to be deployed to the Cloud Foundry space")
|
||||
cmd.Flags().StringVar(&stepConfig.ArtifactVersion, "artifactVersion", os.Getenv("PIPER_artifactVersion"), "The artifact version, used for influx reporting")
|
||||
cmd.Flags().StringVar(&stepConfig.CommitHash, "commitHash", os.Getenv("PIPER_commitHash"), "The commit hash, used for influx reporting")
|
||||
cmd.Flags().StringVar(&stepConfig.CfHome, "cfHome", os.Getenv("PIPER_cfHome"), "The cf home folder used by the cf cli. If not provided the default assumed by the cf cli is used.")
|
||||
cmd.Flags().StringVar(&stepConfig.CfNativeDeployParameters, "cfNativeDeployParameters", os.Getenv("PIPER_cfNativeDeployParameters"), "Additional parameters passed to cf native deployment command")
|
||||
cmd.Flags().StringVar(&stepConfig.CfPluginHome, "cfPluginHome", os.Getenv("PIPER_cfPluginHome"), "The cf plugin home folder used by the cf cli. If not provided the default assumed by the cf cli is used.")
|
||||
@@ -258,6 +262,20 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
Aliases: []config.Alias{},
|
||||
Default: os.Getenv("PIPER_artifactVersion"),
|
||||
},
|
||||
{
|
||||
Name: "commitHash",
|
||||
ResourceRef: []config.ResourceReference{
|
||||
{
|
||||
Name: "commonPipelineEnvironment",
|
||||
Param: "git/headCommitId",
|
||||
},
|
||||
},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
Default: os.Getenv("PIPER_commitHash"),
|
||||
},
|
||||
{
|
||||
Name: "cfHome",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
@@ -530,7 +548,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
Name: "influx",
|
||||
Type: "influx",
|
||||
Parameters: []map[string]interface{}{
|
||||
{"Name": "deployment_data"}, {"fields": []map[string]string{{"name": "artifactUrl"}, {"name": "deployTime"}, {"name": "jobTrigger"}}}, {"tags": []map[string]string{{"name": "artifactVersion"}, {"name": "deployUser"}, {"name": "deployResult"}, {"name": "cfApiEndpoint"}, {"name": "cfOrg"}, {"name": "cfSpace"}}},
|
||||
{"Name": "deployment_data"}, {"fields": []map[string]string{{"name": "artifactUrl"}, {"name": "deployTime"}, {"name": "commitHash"}, {"name": "jobTrigger"}}}, {"tags": []map[string]string{{"name": "artifactVersion"}, {"name": "deployUser"}, {"name": "deployResult"}, {"name": "cfApiEndpoint"}, {"name": "cfOrg"}, {"name": "cfSpace"}}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@@ -290,7 +290,7 @@ func TestCfDeployment(t *testing.T) {
|
||||
}()
|
||||
|
||||
_now = func() time.Time {
|
||||
// There was the big eclise in Karlsruhe
|
||||
// There was the big eclipse in Karlsruhe
|
||||
return time.Date(1999, time.August, 11, 12, 32, 0, 0, time.UTC)
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ func TestCfDeployment(t *testing.T) {
|
||||
|
||||
config.DeployTool = "cf_native"
|
||||
config.ArtifactVersion = "0.1.2"
|
||||
config.CommitHash = "123456"
|
||||
|
||||
influxData := cloudFoundryDeployInflux{}
|
||||
|
||||
@@ -310,6 +311,7 @@ func TestCfDeployment(t *testing.T) {
|
||||
expected.deployment_data.fields.artifactURL = "n/a"
|
||||
expected.deployment_data.fields.deployTime = "AUG 11 1999 12:32:00"
|
||||
expected.deployment_data.fields.jobTrigger = "n/a"
|
||||
expected.deployment_data.fields.commitHash = "123456"
|
||||
|
||||
expected.deployment_data.tags.artifactVersion = "0.1.2"
|
||||
expected.deployment_data.tags.deployUser = "me"
|
||||
|
@@ -7,7 +7,7 @@
|
||||
Deployment can be done
|
||||
|
||||
* in a standard way
|
||||
* in a zero downtime manner (using a [blue-green deployment approach](https://martinfowler.com/bliki/BlueGreenDeployment.html))
|
||||
* in a zero-downtime manner (using a [blue-green deployment approach](https://martinfowler.com/bliki/BlueGreenDeployment.html))
|
||||
|
||||
!!! note "Deployment supports multiple deployment tools"
|
||||
Currently the following are supported:
|
||||
@@ -17,17 +17,17 @@ Deployment can be done
|
||||
|
||||
!!! note
|
||||
Due to [an incompatible change](https://github.com/cloudfoundry/cli/issues/1445) in the Cloud Foundry CLI, multiple buildpacks are not supported by this step.
|
||||
If your `application` contains a list of `buildpacks` instead a single `buildpack`, this will be automatically re-written by the step when blue-green deployment is used.
|
||||
If your `application` contains a list of `buildpacks` instead of a single `buildpack`, this will be automatically re-written by the step when blue-green deployment is used.
|
||||
|
||||
!!! note
|
||||
Cloud Foundry supports the deployment of multiple applications using a single manifest file.
|
||||
This option is supported with project "Piper".
|
||||
In this case define `appName: ''` since the app name for the individual applications have to be defined via the manifest.
|
||||
In this case, define `appName: ''` since the app name for the individual applications has to be defined via the manifest.
|
||||
You can find details in the [Cloud Foundry Documentation](https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#multi-apps)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* Cloud Foundry organization, space and deployment user are available
|
||||
* Cloud Foundry organization, space and deployment users are available
|
||||
* Credentials for deployment have been configured in Jenkins with a dedicated Id
|
||||
|
||||

|
||||
|
@@ -52,6 +52,18 @@ spec:
|
||||
resourceRef:
|
||||
- name: commonPipelineEnvironment
|
||||
param: artifactVersion
|
||||
- name: commitHash
|
||||
type: string
|
||||
description: "The commit hash, used for influx reporting"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
resourceRef:
|
||||
- name: commonPipelineEnvironment
|
||||
param: git/headCommitId
|
||||
- name: cfHome
|
||||
type: string
|
||||
description: "The cf home folder used by the cf cli. If not provided the default assumed by the cf cli is used."
|
||||
@@ -380,6 +392,7 @@ spec:
|
||||
fields:
|
||||
- name: artifactUrl
|
||||
- name: deployTime
|
||||
- name: commitHash
|
||||
- name: jobTrigger
|
||||
tags:
|
||||
- name: artifactVersion
|
||||
|
Reference in New Issue
Block a user