github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/resources/metadata/golangBuild.yaml (about) 1 metadata: 2 name: golangBuild 3 description: This step will execute a golang build. 4 longDescription: | 5 This step will build a golang project. 6 It will also execute golang-based tests using [gotestsum](https://github.com/gotestyourself/gotestsum) and with that allows for reporting test results and test coverage. 7 8 Besides execution of the default tests the step allows for running an additional integration test run using `-tags=integration` using pattern `./...` 9 10 If the build is successful the resulting artifact can be uploaded to e.g. a binary repository automatically. 11 spec: 12 inputs: 13 secrets: 14 - name: golangPrivateModulesGitTokenCredentialsId 15 description: Jenkins 'Username with password' credentials ID containing username/password for http access to your git repos where your go private modules are stored. 16 type: jenkins 17 params: 18 - name: buildFlags 19 type: "[]string" 20 description: Defines list of build flags to be used. 21 scope: 22 - PARAMETERS 23 - STAGES 24 - STEPS 25 - name: buildSettingsInfo 26 type: string 27 description: build settings info is typically filled by the step automatically to create information about the build settings that were used during the maven build . This information is typically used for compliance related processes. 28 scope: 29 - STEPS 30 - STAGES 31 - PARAMETERS 32 resourceRef: 33 - name: commonPipelineEnvironment 34 param: custom/buildSettingsInfo 35 - name: cgoEnabled 36 type: bool 37 description: "If active: enables the creation of Go packages that call C code." 38 scope: 39 - STEPS 40 - STAGES 41 - PARAMETERS 42 - name: coverageFormat 43 type: string 44 description: Defines the format of the coverage repository. 45 possibleValues: 46 - cobertura 47 - html 48 scope: 49 - STEPS 50 - STAGES 51 - PARAMETERS 52 default: html 53 - name: createBOM 54 type: bool 55 description: Creates the bill of materials (BOM) using CycloneDX plugin. It requires Go 1.17 or newer. 56 scope: 57 - GENERAL 58 - STEPS 59 - STAGES 60 - PARAMETERS 61 - name: customTlsCertificateLinks 62 type: "[]string" 63 description: "List of download links to custom TLS certificates. This is required to ensure trusted connections to instances with repositories (like nexus) when publish flag is set to true." 64 scope: 65 - GENERAL 66 - PARAMETERS 67 - STAGES 68 - STEPS 69 - name: excludeGeneratedFromCoverage 70 type: bool 71 description: "Defines if generated files should be excluded, according to [https://golang.org/s/generatedcode](https://golang.org/s/generatedcode)." 72 scope: 73 - PARAMETERS 74 - STAGES 75 - STEPS 76 default: true 77 - name: ldflagsTemplate 78 type: string 79 description: Defines the content of -ldflags option in a golang template format. 80 longDescription: | 81 The template allows using commonPipelineEnvironment parameters in the form `.CPE["<paramName>"]` 82 83 Examples 84 85 * `-X github.com/SAP/jenkins-library/pkg/log.Version={{index .CPE "artifactVersion"}}`. 86 * `-X github.com/SAP/jenkins-library/pkg/log.LibraryRepository={{index .CPE "custom/repositoryId"}}` 87 scope: 88 - PARAMETERS 89 - STAGES 90 - STEPS 91 - name: output 92 type: string 93 description: Defines the build result or output directory as per `go build` documentation. 94 scope: 95 - PARAMETERS 96 - STAGES 97 - STEPS 98 - name: packages 99 type: "[]string" 100 description: List of packages to be build as per `go build` documentation. 101 scope: 102 - PARAMETERS 103 - STAGES 104 - STEPS 105 - name: publish 106 type: bool 107 description: Configures the build to publish artifacts to a repository. 108 scope: 109 - STEPS 110 - STAGES 111 - PARAMETERS 112 - name: targetRepositoryPassword 113 description: "Password for the target repository where the compiled binaries shall be uploaded - typically provided by the CI/CD environment." 114 type: string 115 scope: 116 - PARAMETERS 117 - STAGES 118 - STEPS 119 secret: true 120 resourceRef: 121 - name: commonPipelineEnvironment 122 param: custom/rawRepositoryPassword 123 - name: commonPipelineEnvironment 124 param: custom/repositoryPassword 125 - name: targetRepositoryUser 126 description: "Username for the target repository where the compiled binaries shall be uploaded - typically provided by the CI/CD environment." 127 type: string 128 scope: 129 - PARAMETERS 130 - STAGES 131 - STEPS 132 secret: true 133 resourceRef: 134 - name: commonPipelineEnvironment 135 param: custom/rawRepositoryUsername 136 - name: commonPipelineEnvironment 137 param: custom/repositoryUsername 138 - name: targetRepositoryURL 139 description: "URL of the target repository where the compiled binaries shall be uploaded - typically provided by the CI/CD environment." 140 type: string 141 scope: 142 - PARAMETERS 143 - STAGES 144 - STEPS 145 resourceRef: 146 - name: commonPipelineEnvironment 147 param: custom/rawRepositoryURL 148 - name: commonPipelineEnvironment 149 param: custom/repositoryUrl 150 - name: reportCoverage 151 type: bool 152 description: Defines if a coverage report should be created. 153 default: true 154 scope: 155 - STEPS 156 - STAGES 157 - PARAMETERS 158 - name: runLint 159 type: bool 160 description: Configures the build to run linters with [golangci-lint](https://golangci-lint.run/). 161 scope: 162 - STEPS 163 - STAGES 164 - PARAMETERS 165 - name: runTests 166 type: bool 167 description: Activates execution of tests using [gotestsum](https://github.com/gotestyourself/gotestsum). Tag Go unit tests with 'unit' build tag to exclude them using `--runTests=false` 168 default: true 169 scope: 170 - STEPS 171 - STAGES 172 - PARAMETERS 173 - name: runIntegrationTests 174 type: bool 175 description: Activates execution of a second test run using tag `integration`. 176 scope: 177 - STEPS 178 - STAGES 179 - PARAMETERS 180 - name: targetArchitectures 181 type: "[]string" 182 description: Defines the target architectures for which the build should run using OS and architecture separated by a comma. 183 default: linux,amd64 184 scope: 185 - GENERAL 186 - STEPS 187 - STAGES 188 - PARAMETERS 189 mandatory: true 190 - name: testOptions 191 type: "[]string" 192 description: Options to pass to test as per `go test` documentation (comprises e.g. flags, packages). 193 scope: 194 - STEPS 195 - STAGES 196 - PARAMETERS 197 - name: testResultFormat 198 type: "string" 199 description: Defines the output format of the test results. 200 possibleValues: 201 - junit 202 - standard 203 default: junit 204 scope: 205 - STEPS 206 - STAGES 207 - PARAMETERS 208 - name: privateModules 209 type: "string" 210 description: Tells go which modules shall be considered to be private (by setting [GOPRIVATE](https://pkg.go.dev/cmd/go#hdr-Configuration_for_downloading_non_public_code)). 211 scope: 212 - GENERAL 213 - STEPS 214 - STAGES 215 - PARAMETERS 216 alias: 217 - goprivate 218 - name: privateModulesGitToken 219 description: GitHub personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line. 220 scope: 221 - GENERAL 222 - PARAMETERS 223 - STAGES 224 - STEPS 225 type: string 226 secret: true 227 resourceRef: 228 - name: golangPrivateModulesGitTokenCredentialsId 229 type: secret 230 param: password 231 - type: vaultSecret 232 name: golangPrivateModulesGitTokenVaultSecret 233 default: golang 234 - name: artifactVersion 235 type: string 236 description: Version of the artifact to be built. 237 scope: 238 - GENERAL 239 - PARAMETERS 240 - STAGES 241 - STEPS 242 resourceRef: 243 - name: commonPipelineEnvironment 244 param: artifactVersion 245 - name: golangciLintUrl 246 type: string 247 description: Specifies the download url of the Golangci-Lint Linux amd64 tar binary file. This can be found at https://github.com/golangci/golangci-lint/releases. 248 scope: 249 - PARAMETERS 250 - STEPS 251 default: "https://github.com/golangci/golangci-lint/releases/download/v1.51.2/golangci-lint-1.51.2-linux-amd64.tar.gz" 252 outputs: 253 resources: 254 - name: commonPipelineEnvironment 255 type: piperEnvironment 256 params: 257 - name: custom/buildSettingsInfo 258 - name: custom/artifacts 259 type: "piperenv.Artifacts" 260 - name: reports 261 type: reports 262 params: 263 - filePattern: "**/bom-golang.xml" 264 type: sbom 265 - filePattern: "**/TEST-*.xml" 266 type: junit 267 - filePattern: "**/cobertura-coverage.xml" 268 type: cobertura-coverage 269 containers: 270 - name: golang 271 image: golang:1 272 options: 273 - name: -u 274 value: "0"