You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	feat(pipelineCreateSummary): enhance content with reference link (#2837)
* feat(pipelineCreateSummary): enhance content with reference link * Update cmd/pipelineCreateScanSummary.go * Update cmd/pipelineCreateScanSummary.go
This commit is contained in:
		| @@ -2,6 +2,7 @@ package cmd | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/SAP/jenkins-library/pkg/log" | ||||
| @@ -58,6 +59,9 @@ func runPipelineCreateScanSummary(config *pipelineCreateScanSummaryOptions, tele | ||||
| 	} | ||||
|  | ||||
| 	output := []byte{} | ||||
| 	if len(config.PipelineLink) > 0 { | ||||
| 		output = []byte(fmt.Sprintf("## Pipeline Source for Details\n\n[%v](%v)\n\n", config.PipelineLink, config.PipelineLink)) | ||||
| 	} | ||||
| 	for _, scanReport := range scanReports { | ||||
| 		if (config.FailedOnly && !scanReport.SuccessfulScan) || !config.FailedOnly { | ||||
| 			mdReport, _ := scanReport.ToMarkdown() | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import ( | ||||
| type pipelineCreateScanSummaryOptions struct { | ||||
| 	FailedOnly     bool   `json:"failedOnly,omitempty"` | ||||
| 	OutputFilePath string `json:"outputFilePath,omitempty"` | ||||
| 	PipelineLink   string `json:"pipelineLink,omitempty"` | ||||
| } | ||||
|  | ||||
| // PipelineCreateScanSummaryCommand Collect scan result information anc create a summary report | ||||
| @@ -96,6 +97,7 @@ It is for example used to create a markdown file which can be used to create a G | ||||
| func addPipelineCreateScanSummaryFlags(cmd *cobra.Command, stepConfig *pipelineCreateScanSummaryOptions) { | ||||
| 	cmd.Flags().BoolVar(&stepConfig.FailedOnly, "failedOnly", false, "Defines if only failed scans should be included into the summary.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.OutputFilePath, "outputFilePath", `scanSummary.md`, "Defines the filepath to the target file which will be created by the step.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.PipelineLink, "pipelineLink", os.Getenv("PIPER_pipelineLink"), "Link to the pipeline (e.g. Jenkins job url) for reference in the scan summary.") | ||||
|  | ||||
| } | ||||
|  | ||||
| @@ -126,6 +128,14 @@ func pipelineCreateScanSummaryMetadata() config.StepData { | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "pipelineLink", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
|   | ||||
| @@ -71,6 +71,26 @@ func TestRunPipelineCreateScanSummary(t *testing.T) { | ||||
| 		assert.Contains(t, fileContentString, "Title Scan 3") | ||||
| 	}) | ||||
|  | ||||
| 	t.Run("success - with source link", func(t *testing.T) { | ||||
| 		t.Parallel() | ||||
|  | ||||
| 		config := pipelineCreateScanSummaryOptions{ | ||||
| 			OutputFilePath: "scanSummary.md", | ||||
| 			PipelineLink:   "https://test.com/link", | ||||
| 		} | ||||
|  | ||||
| 		utils := newPipelineCreateScanSummaryTestsUtils() | ||||
|  | ||||
| 		err := runPipelineCreateScanSummary(&config, nil, utils) | ||||
|  | ||||
| 		assert.NoError(t, err) | ||||
| 		reportExists, _ := utils.FileExists("scanSummary.md") | ||||
| 		assert.True(t, reportExists) | ||||
| 		fileContent, _ := utils.FileRead("scanSummary.md") | ||||
| 		fileContentString := string(fileContent) | ||||
| 		assert.Contains(t, fileContentString, "https://test.com/link") | ||||
| 	}) | ||||
|  | ||||
| 	t.Run("error - read file", func(t *testing.T) { | ||||
| 		t.Skip() | ||||
| 		//ToDo | ||||
|   | ||||
| @@ -23,3 +23,10 @@ spec: | ||||
|           - STEPS | ||||
|         type: string | ||||
|         default: scanSummary.md | ||||
|       - name: pipelineLink | ||||
|         description: Link to the pipeline (e.g. Jenkins job url) for reference in the scan summary. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         type: string | ||||
|   | ||||
		Reference in New Issue
	
	Block a user