Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/server/openapi/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5073,6 +5073,9 @@ const docTemplate = `{
"refspec": {
"type": "string"
},
"rerun_count": {
"type": "integer"
},
"reviewed": {
"type": "integer"
},
Expand Down Expand Up @@ -6011,6 +6014,9 @@ const docTemplate = `{
"parent": {
"type": "integer"
},
"rerun_count": {
"type": "integer"
},
"started": {
"type": "integer"
},
Expand Down
191 changes: 96 additions & 95 deletions docs/docs/20-usage/50-environment.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions e2e/scenarios/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ func TestRestartPipeline(t *testing.T) {
assert.NotEqual(t, originalFinished.ID, restarted.ID, "restart should have a new ID")
assert.NotEqual(t, originalFinished.Number, restarted.Number, "restart should have a new number")
assert.Equal(t, originalFinished.Number, restarted.Parent, "restart.Parent should point at original.Number")
assert.Equal(t, int64(1), restarted.RerunCount, "restart should increment rerun count")

// The restart runs through the same start path — wait for it to finish.
restartedFinished := setup.WaitForPipeline(t, env.Store, restarted.ID)
assert.Equal(t, model.StatusSuccess, restartedFinished.Status, "restarted pipeline should succeed")
assert.Equal(t, int64(1), restartedFinished.RerunCount, "restarted pipeline should preserve rerun count")

// Restart should have its OWN workflows, not reuse the originals.
restartedWorkflows, err := env.Store.WorkflowGetTree(restartedFinished)
Expand Down
3 changes: 3 additions & 0 deletions pipeline/frontend/metadata/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (m *Metadata) Environ() map[string]string {
setNonEmptyEnvVar(params, "CI_PIPELINE_STARTED", strconv.FormatInt(pipeline.Started, 10))
setNonEmptyEnvVar(params, "CI_PIPELINE_AUTHOR", pipeline.Author)
setNonEmptyEnvVar(params, "CI_PIPELINE_AVATAR", pipeline.Avatar)
if pipeline.RerunCount > 0 {
setNonEmptyEnvVar(params, "CI_PIPELINE_RERUNS", strconv.FormatInt(pipeline.RerunCount, 10))
}

workflow := m.Workflow
setNonEmptyEnvVar(params, "CI_WORKFLOW_NAME", workflow.Name)
Expand Down
1 change: 1 addition & 0 deletions pipeline/frontend/metadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type (
DeployTask string `json:"task,omitempty"`
Commit Commit `json:"commit"`
Parent int64 `json:"parent,omitempty"`
RerunCount int64 `json:"rerun_count,omitempty"`
Cron string `json:"cron,omitempty"`
Author string `json:"author,omitempty"`
Avatar string `json:"avatar,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions server/model/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Pipeline struct {
DeployTask string `json:"deploy_task" xorm:"deploy_task"`
Commit string `json:"commit" xorm:"commit"`
Branch string `json:"branch" xorm:"branch"`
RerunCount int64 `json:"rerun_count" xorm:"rerun_count"`
Ref string `json:"ref" xorm:"ref"`
Refspec string `json:"refspec" xorm:"refspec"`
Title string `json:"title" xorm:"title"`
Expand Down
1 change: 1 addition & 0 deletions server/pipeline/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func metadataPipelineFromModelPipeline(pipeline *model.Pipeline, includeParent b
Event: metadata.Event(pipeline.Event),
EventReason: pipeline.EventReason,
ForgeURL: pipeline.ForgeURL,
RerunCount: pipeline.RerunCount,
DeployTo: pipeline.DeployTo,
DeployTask: pipeline.DeployTask,
Commit: metadata.Commit{
Expand Down
21 changes: 21 additions & 0 deletions server/pipeline/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ func TestGetWorkflowMetadata(t *testing.T) {
"CI_SYSTEM_NAME": "woodpecker", "CI_SYSTEM_URL": "https://example.com", "CI_WORKFLOW_NAME": "hello", "CI_WORKFLOW_NUMBER": "0",
},
},
{
name: "Test with Pipeline RerunCount",
pipeline: &model.Pipeline{Number: 3, Parent: 2, RerunCount: 1},
expectedMetadata: metadata.Metadata{Sys: metadata.System{Name: "woodpecker"}, Curr: metadata.Pipeline{
Number: 3,
Parent: 2,
RerunCount: 1,
}},
expectedEnviron: map[string]string{
"CI": "woodpecker",
"CI_PIPELINE_CREATED": "0", "CI_PIPELINE_FILES": "[]", "CI_PIPELINE_NUMBER": "3",
"CI_PIPELINE_PARENT": "2", "CI_PIPELINE_STARTED": "0", "CI_PIPELINE_URL": "/repos/0/pipeline/3",
"CI_PIPELINE_RERUNS": "1",
"CI_PREV_PIPELINE_CREATED": "0",
"CI_PREV_PIPELINE_FINISHED": "0", "CI_PREV_PIPELINE_NUMBER": "0", "CI_PREV_PIPELINE_PARENT": "0",
"CI_PREV_PIPELINE_STARTED": "0", "CI_PREV_PIPELINE_URL": "/repos/0/pipeline/0",
"CI_REPO_PRIVATE": "false", "CI_REPO_TRUSTED": "false", "CI_REPO_TRUSTED_NETWORK": "false", "CI_REPO_TRUSTED_SECURITY": "false", "CI_REPO_TRUSTED_VOLUMES": "false",
"CI_STEP_NUMBER": "0", "CI_STEP_URL": "/repos/0/pipeline/3", "CI_SYSTEM_NAME": "woodpecker",
"CI_WORKFLOW_NUMBER": "0",
},
},
}

for _, testCase := range testCases {
Expand Down
1 change: 1 addition & 0 deletions server/pipeline/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin

newPipeline := createNewOutOfOld(lastPipeline)
newPipeline.Parent = lastPipeline.Number
newPipeline.RerunCount++
newPipeline.Version = version.String()

err = store.CreatePipeline(newPipeline)
Expand Down