Harbor integration cannot list untagged artifacts: undefined method `map' for nil:NilClass
Summary
If an artifact in Harbor is not tagged, Gitlab will display an integration error message and the list of tags will not be shown.
With Harbor integration set up, this error occurs when there is no tag attached to the artifact in Harbor.
Steps to reproduce
- Setup integration with Harbor
- Push any tagged image to Harbor project registry
- Push same tagged image but with different SHA
- Remove tag from any of artifacts in Harbor project
What is the current bug behavior?
What is the expected correct behavior?
List of tagged artifacts.
Relevant logs and/or screenshots
The following error is shown in production_json.log:
{
"method": "GET",
"path": "/mygroup/myproject/-/harbor/repositories/myproject/artifacts.json",
"format": "json",
"controller": "Projects::Harbor::ArtifactsController",
"action": "index",
"status": 500,
...
"meta.caller_id": "Projects::Harbor::ArtifactsController#index",
"meta.feature_category": "integrations",
...
"exception.class": "NoMethodError",
"exception.message": "undefined method `map' for nil:NilClass",
"exception.backtrace": [
"app/serializers/integrations/harbor_serializers/artifact_entity.rb:25:in `block in <class:ArtifactEntity>'",
"grape-entity (1.0.1) lib/grape_entity/entity.rb:518:in `instance_exec'",
"grape-entity (1.0.1) lib/grape_entity/entity.rb:518:in `exec_with_object'",
"grape-entity (1.0.1) lib/grape_entity/exposure/block_exposure.rb:10:in `value'",
"grape-entity (1.0.1) lib/grape_entity/exposure/base.rb:91:in `valid_value'",
"grape-entity (1.0.1) lib/grape_entity/exposure/base.rb:73:in `serializable_value'",
"grape-entity (1.0.1) lib/grape_entity/exposure/nesting_exposure.rb:41:in `block in serializable_value'",
...
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Debian 11 Current User: git Using RVM: no Ruby Version: 3.1.4p223 Gem Version: 3.4.22 Bundler Version:2.5.4 Rake Version: 13.0.6 Redis Version: 7.0.14 Sidekiq Version:7.1.6 Go Version: unknown GitLab information Version: 16.8.0 Revision: 16896fceb7a Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 13.12 URL: https://gitlab.company.local HTTP Clone URL: https://gitlab.company.local/some-group/some-project.git SSH Clone URL: git@gitlab.company.local:some-group/some-project.git Using LDAP: no Using Omniauth: yes Omniauth Providers: openid_connect GitLab Shell Version: 14.32.0 Repository storages: - default: unix:/var/opt/gitlab/gitaly/gitaly.socket GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Gitaly - default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket - default Version: 16.8.0 - default Git Version: 2.42.0
Additional details & possible fixes
-
It seems that Gitlab is trying to get tags for all artifacts that are present in the project and cannot do this. It's happening in https://gitlab.com/gitlab-org/gitlab/-/blob/v17.10.4-ee/app/serializers/integrations/harbor_serializers/artifact_entity.rb?ref_type=tags#L25. It's probably worth adding logic that would only output tagged artifacts and ignore untagged OR show both tagged and untagged artifacts.
-
Looks like it is a common case when artifacts are not having tags in Harbor, see https://github.com/goharbor/harbor/issues/19157. The same issue was reported on the Harbor side, but it was auto-closed: https://github.com/goharbor/harbor/issues/19974. In this issue, Harbor representatives suggested a workaround:
Although it does not solve the root problem, one thing you can do to mitigate this risk is to setup a cleanup task that is scheduled as often as you want via a cron expression. This can delete untagged artifacts. This is done in the "Clean up" section. Make sure you activate the option "Allow garbage collection on untagged artifacts"

