Skip to content

GitLab Next

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
GitLab
GitLab
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 34,888
    • Issues 34,888
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 1,214
    • Merge Requests 1,214
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Metrics
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • GitLab.org
  • GitLabGitLab
  • Issues
  • #5582

Closed
Open
Opened Apr 06, 2018 by Damian Nowak@NowakerContributor

Add missing actions and data to Environments and Deployments APIs

Problem

Review apps are short lived by definition. Unfortunately, stale branches are ubiquitous (gitlab-ce has ~1,600). Keeping all as review apps would is already a burden for us. It's not possible to write a script because

Proposal

We want to write a script that periodically deletes old environments. However, it's not possible to implement it because Environments and Deployments APIs don't provide enough information.

environments = get "/projects/#{project_id.urlencode}/environments"
environments.each do |environment|
  next unless environment.available?
  deployment = get "/projects/#{project_id.urlencode}/deployments/#{environment.deployment_id.urlencode}"
  next if deployment.created_at >= 2.weeks.ago
  next if deployment.deployable.name != 'reviewapp-deploy' # VERY IMPORTANT! We only want to delete review apps, right?!
  post "/projects/#{project_id.urlencode}/environments/#{environment.id.urlencode}/stop"
end

Missing API functionality to be added

Status: available or stopped.

  • Endpoint /projects/:id/environments
  • Access the state field from the API
  • When the model is instantiated, state machine helper methods are available available?, stopped?

Deployment ID of the current deployment

  • Endpoint /projects/:id/environments
  • field last_deployment exposed https://gitlab.com/gitlab-org/gitlab/blob/master/app/models/environment.rb#L11
  • last_deployment is an Entities::Deployment object, so this call is not necessary: deployment = get "/projects/#{project_id.urlencode}/deployments/#{environment.deployment_id.urlencode}"

Add missing API end-point (Rails: def show)

  • This endpoint exists - no changes needed GET /projects/:id/environments/:environment_id
  • https://docs.gitlab.com/ee/api/environments.html#get-a-specific-environment - added in April 2019 724f19ba

Links / references

  • https://gitlab.com/gitlab-org/gitlab-ce/issues/42822

~"feature proposal" ~"CI/CD" ~kubernetes

@ayufan @markglenfletcher @markpundsack @bikebilly @victorwu

Edited Sep 26, 2019 by Damian Nowak
Assignee
Assign to
12.4
Milestone
12.4 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: gitlab-org/gitlab#5582