Skip to content

Duplicates in CI needs causes 500 response

Summary

Hit 'Create new pipeline' and see a 500 error.

Steps to reproduce

You need a .gitlab-ci.yaml with somethings like

job_1:
   stage: test
   script: do something
job_2:
  stage: build
  script: do something else
  needs: ['job_1', 'job_1']

Example Project

https://gitlab.com/mcfedr/ci-needs-bug/pipelines

What is the current bug behavior?

500 error.

What is the expected correct behavior?

CI Lint error

Text for the error:

<job1> has duplicate entries in the needs section.

Relevant logs and/or screenshots

{
	"method": "POST",
	"path": "/my_project_app/my_project_app/pipelines",
	"format": "html",
	"controller": "Projects::PipelinesController",
	"action": "create",
	"status": 500,
	"duration": 333.56,
	"view": 0.0,
	"db": 74.82,
	"time": "2019-11-28T14:38:17.931Z",
	"params": [{
		"key": "utf8",
		"value": "✓"
	}, {
		"key": "authenticity_token",
		"value": "[FILTERED]"
	}, {
		"key": "pipeline",
		"value": {
			"ref": "dev"
		}
	}, {
		"key": "namespace_id",
		"value": "my_project_app"
	}, {
		"key": "project_id",
		"value": "my_project_app"
	}],
	"remote_ip": "78.137.6.142",
	"user_id": 2,
	"username": "mcfedr",
	"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:70.0) Gecko/20100101 Firefox/70.0",
	"queue_duration": null,
	"rugged_calls": 3,
	"rugged_duration_ms": 32.36,
	"correlation_id": "aSjNGDOR3Ha",
	"cpu_s": 0.19548780199997395,
	"exception": {
		"class": "ActiveRecord::RecordNotUnique",
		"message": "PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint \"index_ci_build_needs_on_build_id_and_name\"\nDETAIL:  Key (build_id, name)=(299299, test) already exists.\n: INSERT INTO \"ci_build_needs\" (\"build_id\", \"name\") VALUES (299299, 'test') RETURNING \"id\"",
		"backtrace": ["lib/gitlab/ci/pipeline/chain/create.rb:11:in `perform!'", "lib/gitlab/ci/pipeline/chain/sequence.rb:19:in `block in build!'", "lib/gitlab/ci/pipeline/chain/sequence.rb:16:in `each'", "lib/gitlab/ci/pipeline/chain/sequence.rb:16:in `build!'", "app/services/ci/create_pipeline_service.rb:53:in `execute'", "app/controllers/projects/pipelines_controller.rb:62:in `create'", "lib/gitlab/session.rb:11:in `with_session'", "app/controllers/application_controller.rb:450:in `set_session_storage'", "app/controllers/application_controller.rb:444:in `set_locale'"]
	}
}

Possible fixes

(If you can, link to the line of code that might be responsible for the problem)

Edited by Nadia Sotnikova