Skip to content

Commit

Permalink
feat: Add Jenkins job parameter to workflow report
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesin11 committed May 21, 2020
1 parent baa8e39 commit 7c8578f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
17 changes: 17 additions & 0 deletions bigquery_schema/workflow_report.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,22 @@
"mode": "REPEATED",
"name": "jobs",
"type": "RECORD"
},
{
"fields": [
{
"mode": "NULLABLE",
"name": "name",
"type": "STRING"
},
{
"mode": "NULLABLE",
"name": "value",
"type": "STRING"
}
],
"mode": "REPEATED",
"name": "parameters",
"type": "RECORD"
}
]
6 changes: 6 additions & 0 deletions src/analyzer/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type WorkflowReport = {
workflowDurationSec: number
sumJobsDurationSec: number
successCount: 0 | 1 // = 'SUCCESS': 1, others: 0. For create average success rate in dashboard
parameters: JobParameter[]
}

export type JobReport = {
Expand All @@ -45,6 +46,11 @@ export type StepReport = {
stepDurationSec: number
}

type JobParameter = {
name: string
value: string
}

export interface Analyzer {
createWorkflowReport(...args: any[]): WorkflowReport
}
Expand Down
2 changes: 2 additions & 0 deletions src/analyzer/circleci_analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type WorkflowReport = {
workflowDurationSec: number // = sum(job jobDurationSec)
sumJobsDurationSec: number // = sum(jobs sumStepsDurationSec)
successCount: 0 | 1 // = 'SUCCESS': 1, others: 0
parameters: [] // CircleciAnalyzer does not support output build parameters yet
}

type JobReport = {
Expand Down Expand Up @@ -115,6 +116,7 @@ export class CircleciAnalyzer implements Analyzer {
workflowDurationSec: secRound(sumBy(jobReports, 'jobDurationSec')),
sumJobsDurationSec: secRound(sumBy(jobReports, 'sumStepsDurationSec')),
successCount: (status === 'SUCCESS') ? 1 : 0,
parameters: [],
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/analyzer/github_analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type WorkflowReport = {
workflowDurationSec: number // = completedAt - startedAt
sumJobsDurationSec: number // = sum(jobs sumStepsDurationSec)
successCount: 0 | 1 // = 'SUCCESS': 1, others: 0
parameters: [] // GithubAnalyzer does not support build parameters yet
}

type JobReport = {
Expand Down Expand Up @@ -113,6 +114,7 @@ export class GithubAnalyzer implements Analyzer {
workflowDurationSec: diffSec(startedAt, completedAt),
sumJobsDurationSec: sumBy(jobReports, 'sumStepsDurationSec'),
successCount: (status === 'SUCCESS') ? 1 : 0,
parameters: []
}
}

Expand Down
17 changes: 12 additions & 5 deletions src/analyzer/jenkins_analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type WorkflowReport = {
workflowDurationSec: number // = durationMillis / 1000
sumJobsDurationSec: number // = sum(jobs sumStepsDurationSec)
successCount: 0 | 1 // = 'SUCCESS': 1, others: 0
parameters: JobParameter[]
}

type JobReport = {
Expand All @@ -46,6 +47,11 @@ type StepReport = {
stepDurationSec: number // durationMillis / 1000
}

type JobParameter = {
name: string
value: string
}

export class JenkinsAnalyzer implements Analyzer {
constructor() { }

Expand Down Expand Up @@ -102,6 +108,7 @@ export class JenkinsAnalyzer implements Analyzer {
workflowDurationSec: run.durationMillis / 1000,
sumJobsDurationSec: secRound(sumBy(jobReports, 'sumStepsDurationSec')),
successCount: (status === 'SUCCESS') ? 1 : 0,
parameters: this.detectParameters(build),
}
}

Expand Down Expand Up @@ -183,14 +190,14 @@ export class JenkinsAnalyzer implements Analyzer {
}
}

detectParameters(build: BuildResponse): {[key: string]: string} {
detectParameters(build: BuildResponse): JobParameter[] {
const action = build.actions.find((action) => {
return action._class === "hudson.model.ParametersAction"
}) as ParametersAction | undefined
if (!action) return {}
if (!action) return []

return Object.fromEntries(
action.parameters.map((obj) => [obj.name, obj.value])
)
return action.parameters.map((param) => {
return { name: param.name, value: String(param.value ?? '') }
})
}
}
4 changes: 2 additions & 2 deletions src/client/jenkins_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ export type ParametersAction = {
_class: "hudson.model.ParametersAction"
parameters:
{
_class: "hudson.model.StringParameterValue"
_class: string // ex: "hudson.model.StringParameterValue"
name: string // "TIMEOUT",
value: string // "10"
value?: string | number | boolean // "10"
}[]
}

Expand Down

0 comments on commit 7c8578f

Please sign in to comment.