Skip to content

Commit

Permalink
feat: provide short revision in ARGOCD_APP_REVISION_SHORT env variable (
Browse files Browse the repository at this point in the history
argoproj#14926)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
  • Loading branch information
alexmt authored and tesla59 committed Dec 16, 2023
1 parent 8247914 commit 90a78cb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/user-guide/build-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
[Custom tools](../operator-manual/config-management-plugins.md), [Helm](helm.md), [Jsonnet](jsonnet.md), and [Kustomize](kustomize.md) support the following build env vars:

| Variable | Description |
| ----------------------------------- | ----------------------------------------------------------------------- |
|-------------------------------------|-------------------------------------------------------------------------|
| `ARGOCD_APP_NAME` | The name of the application. |
| `ARGOCD_APP_NAMESPACE` | The destination namespace of the application. |
| `ARGOCD_APP_REVISION` | The resolved revision, e.g. `f913b6cbf58aa5ae5ca1f8a2b149477aebcbd9d8`. |
| `ARGOCD_APP_REVISION_SHORT` | The resolved short revision, e.g. `f913b6c`. |
| `ARGOCD_APP_SOURCE_PATH` | The path of the app within the source repo. |
| `ARGOCD_APP_SOURCE_REPO_URL` | The source repo URL. |
| `ARGOCD_APP_SOURCE_TARGET_REVISION` | The target revision from the spec, e.g. `master`. |
Expand Down
5 changes: 5 additions & 0 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,10 +1412,15 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
}

func newEnv(q *apiclient.ManifestRequest, revision string) *v1alpha1.Env {
shortRevision := revision
if len(shortRevision) > 7 {
shortRevision = shortRevision[:7]
}
return &v1alpha1.Env{
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_NAME", Value: q.AppName},
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_NAMESPACE", Value: q.Namespace},
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_REVISION", Value: revision},
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_REVISION_SHORT", Value: shortRevision},
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_SOURCE_REPO_URL", Value: q.Repo.Repo},
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_SOURCE_PATH", Value: q.ApplicationSource.Path},
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_SOURCE_TARGET_REVISION", Value: q.ApplicationSource.TargetRevision},
Expand Down
1 change: 1 addition & 0 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,7 @@ func Test_newEnv(t *testing.T) {
&argoappv1.EnvEntry{Name: "ARGOCD_APP_NAME", Value: "my-app-name"},
&argoappv1.EnvEntry{Name: "ARGOCD_APP_NAMESPACE", Value: "my-namespace"},
&argoappv1.EnvEntry{Name: "ARGOCD_APP_REVISION", Value: "my-revision"},
&argoappv1.EnvEntry{Name: "ARGOCD_APP_REVISION_SHORT", Value: "my-revi"},
&argoappv1.EnvEntry{Name: "ARGOCD_APP_SOURCE_REPO_URL", Value: "https://github.com/my-org/my-repo"},
&argoappv1.EnvEntry{Name: "ARGOCD_APP_SOURCE_PATH", Value: "my-path"},
&argoappv1.EnvEntry{Name: "ARGOCD_APP_SOURCE_TARGET_REVISION", Value: "my-target-revision"},
Expand Down

0 comments on commit 90a78cb

Please sign in to comment.