For the complete documentation index, see llms.txt. This page is also available as Markdown.

GitOps

Use the Harness CLI to manage the GitOps module, including agents, applications, destination clusters, source repositories, ApplicationSets, and Argo CD AppProject mappings.

Harness GitOps is backed by Argo CD. A GitOps agent runs as the control plane inside your cluster, and applications, destination clusters, source repositories, and ApplicationSets are registered against that agent. The CLI lets you register and inspect all of these resources, trigger syncs, and refresh application state without opening the Harness UI or the Argo CD console. It also lets you map and import existing Argo CD AppProjects.

This page covers all GitOps resources and actions available in the CLI.


What you will learn in this topic

By the end of this page, you will know how to:

  • List, create, and delete GitOps agents, and fetch the manifests that install them.

  • Create, update, and delete GitOps applications.

  • Sync and refresh an application.

  • Register destination clusters and source repositories against an agent.

  • Manage ApplicationSets.

  • Discover Argo CD AppProjects, map them to a Harness org and project, and import the mapped projects.

  • Watch the auto-create log for services, environments, and cluster links that an import creates.


Before you begin

  • Harness CLI installed and authenticated: Go to Install and upgrade and Authenticate to set up the CLI.

  • Project scope configured: GitOps resources require --org and --project. Set them in your profile or pass them on each command.

  • Cluster access: To install an agent you need helm or kubectl access to the target cluster. The CLI produces the install manifest but does not apply it for you.


Resource identifiers

Agents are top-level resources. Everything else is registered against an agent, so it uses a compound identifier:

  • <agent>/<name>: An application, cluster, or repository on an agent.

  • <agent>/<uuid>: An ApplicationSet on an agent.

  • <agent>/<argo_project>: An AppProject mapping on an agent.

Leave the slash in a compound identifier unencoded. Go to Global flags and output for the --set, -f, --format, paging, and scope conventions that apply to every command on this page.


Agents

A GitOps agent is the control plane that runs in your cluster and reconciles desired state from Git against live state in the cluster. Create the agent record in Harness first, then install the agent workload into the cluster.

List agents

Filter agents by type, scope, health, or connection state.

Get agent details

Create an agent

Create the agent record in Harness. This registers the agent but does not install anything into a cluster.

Get the agent install manifest

Fetch the Helm override values or the kubectl manifest that installs the agent into a cluster. --output_file is required. Pass -f to supply install options from a file.

This command writes the install artifact to disk. It does not run helm or kubectl for you. Apply the generated file against your cluster as a separate step.

Delete an agent


Applications

A GitOps application maps a source Git revision to a destination cluster and namespace. Harness reconciles the application continuously and reports drift between the desired state in Git and the live state in the cluster.

List applications

Get application details

Use --yaml to return the Argo CD application spec.

Create an application

-f and --cluster are both required. Pass --repo to bind the application to a registered source repository, or --skip-repo-validation to create the application without validating the repository.

Update an application

Sync an application

Trigger a sync to reconcile the cluster with the desired state in Git. Use --revision to sync a specific Git revision, --prune to remove resources that no longer exist in Git, and --dry-run to preview the sync without applying it.

Refresh an application

Refresh the application state from its source. Add --hard to invalidate the manifest caches before the refresh.

Delete an application

Control how the deletion cascades to the resources the application manages.


Clusters

A GitOps cluster is a deployment destination that an agent can reach. Register a cluster on an agent before you point an application at it.

List and get clusters

Register a cluster

Add --upsert to update the cluster if it is already registered instead of failing.

Update a cluster

Delete a cluster


Repositories

A GitOps repository is a source of desired state. Register the Git repository on an agent so that applications can read manifests from it.

List and get repositories

Register a repository

Add --upsert to update an existing registration. Pass --repo-creds-id to reuse stored repository credentials.

Update a repository

Delete a repository


ApplicationSets

An ApplicationSet generates GitOps applications from a template and a generator, so one definition can fan out across many clusters, namespaces, or Git directories. ApplicationSets are identified by agent and UUID.

List and get ApplicationSets

Create an ApplicationSet

Add --upsert to update an existing ApplicationSet, or --dry-run to validate the definition without creating anything.

Update an ApplicationSet

Delete an ApplicationSet


Argo CD AppProject mappings

If you run Argo CD AppProjects that Harness does not yet know about, use these commands to discover them on an agent, map each one to a Harness org and project, and import the mapped projects. Mapping and import are scriptable, so you can migrate many AppProjects without using the mapping UI on the GitOps Agent page. For the equivalent UI flow, go to GitOps Agent.

Use an account- or org-level agent for this workflow. A project-level agent can only map AppProjects to the single project it already belongs to.

List Argo CD projects

List the Argo CD AppProjects visible to an agent, including ones that are not yet mapped to a Harness project.

Pass --level account|org|project to match the agent's own scope, or skip --level and prefix the agent ID with its scope instead. For an account-scoped agent, pass account.<agent_id> instead of the bare agent ID with --level account; for an org- or project-scoped agent, pass the ID with the matching --level or its scope-prefixed form. A --level that does not match the agent's actual scope returns a 404. Each row of output shows the Argo CD project's name, description, and created timestamp.

List AppProject mappings

Each row shows the Argo CD project, the Harness org and project it maps to, and whether auto-create is on. An agent with no mappings returns an empty table.

Create an AppProject mapping

Map an Argo CD AppProject to a Harness org and project. Set autoCreateServiceEnv to true so that import also creates the services, environments, and cluster links that the AppProject's applications need. It defaults to false when omitted.

To create multiple mappings in a single command, pass a file instead of --set.

Mappings file example

A row in the -f file that is missing argoproject, org, or project, or --set without all three, is rejected before Harness makes an API call. You cannot combine -f with --set, pass an empty mappings list, repeat the same argoproject more than once in the same file, or leave a row in the file incomplete. Mapping an AppProject that is already mapped returns an error instead of creating a duplicate mapping. The Harness org and project in each row must already exist, and all rows in the file succeed or fail together: if one row is invalid, Harness creates none of the mappings in that call.

Update an AppProject mapping

The org and project are lookup keys in the mapping, so updates only change autoCreateServiceEnv. All three of org, project, and autoCreateServiceEnv are required on every update call, autoCreateServiceEnv must be true or false, and a mapping that does not exist for the given org and project returns a 404. To move a mapping to a different org or project, delete it and create it again.

Delete an AppProject mapping

Deleting a mapping also removes the applications, ApplicationSets, repositories, and clusters that Harness associated with that Argo CD project.

Delete takes org and project through --set only, not -f. Omitting either value is rejected before Harness makes an API call, and a mapping that does not exist for the given org and project returns a 404.

Import AppProject mappings

Import brings the applications, clusters, and repositories for one or more mapped Argo CD AppProjects into Harness. When a mapping has autoCreateServiceEnv: true, import also starts the background creation of the corresponding services, environments, and cluster links, and returns an importRequestId you can use to track the work.

To import from a file instead of --argo-project-names:

Import file example

You cannot pass both --argo-project-names and -f, and you must pass one of them. The project list cannot be empty, and importing an Argo CD project without a mapping returns an error.

The default text summary shows the import counts per project, the importRequestId, and how many services, environments, and cluster links Harness plans to auto-create. The Harness CLI only asks about watching when auto-create is on for the mapping and the planned auto-create count is greater than zero. When it asks, the prompt is Watch auto-create logs now? [y/N] and the default answer is No. If auto-create is off, or the planned count is zero, or the import response has no importRequestId, the Harness CLI skips the prompt and does not watch, regardless of --watch.

A WATCH STARTED FROM IMPORT STOPS ON ITS OWN

The watch stops as soon as the auto-create log total reaches the planned count, or after the default two-minute window elapses, and exits 0 either way. Press Ctrl-C to cancel the watch instead; a canceled watch exits with a non-zero code.

If you skip the watch, or the planned count is zero, the summary still prints the equivalent list gitops_autocreate_log command so that you can check the outcome later.

Watch auto-create logs

Fetch or follow the auto-create log for a specific import. Each row records whether a service, environment, or cluster link succeeded (SUCCESS), succeeded with a warning (WARNING), or failed (FAILED), with the failure reason as the last column. All three outcomes count toward the planned total when a watch was started from import. Harness writes these rows asynchronously after import returns, and retains them for seven days.

Use the shared pagination flags to control how much of the log you fetch. Go to Pagination flags to configure how much of the log you fetch.

--import-request-id is required. --watch always fetches the full log, so you cannot combine it with --offset, --limit, or --count; --all cannot be combined with --offset or --limit; and --count cannot be combined with --all, --offset, or --limit. While --watch polls, it prints the current status plus any rows that are new or changed since the last poll, rather than reprinting the full table each time.

A standalone --watch call, one that you did not start from import, polls until it times out or you press Ctrl-C. It does not stop early at a planned count, because Harness only knows that planned count when the import itself is running.

Example: migrate several Argo CD AppProjects in one script

The following script chains the commands on this page to discover, map, import, and verify a batch of Argo CD AppProjects without touching the Harness UI.

Step 4 waits inline because of --watch, so by the time the script continues, the import has either finished or hit its two-minute timeout. Drop --watch and run step 5 on a schedule instead if you would rather poll for completion from outside the script.


Last updated

Was this helpful?