github.com/argoproj/argo-cd/v3@v3.2.1/docs/user-guide/plugins.md (about) 1 # Plugins 2 3 ## Overview 4 5 This guide demonstrates how to write plugins for the 6 `argocd` CLI tool. Plugins are a way to extend `argocd` CLI with new sub-commands, 7 allowing for custom features which are not part of the default distribution 8 of the `argocd` CLI.. 9 10 If you would like to take a look at the original proposal, head over to this [enhancement proposal](../proposals/argocd-cli-pluin.md). 11 It covers how the plugin mechanism works, its benefits, motivations, and the goals it aims to achieve. 12 13 ## Prerequisites 14 15 You need to have a working `argocd` binary installed locally. You can follow 16 the [cli installation documentation](https://argo-cd.readthedocs.io/en/stable/cli_installation/) to install the binary. 17 18 ## Create `argocd` plugins 19 20 A plugin is a standalone executable file whose name begins with argocd-. 21 To install a plugin, move its executable file to any directory included in your PATH. 22 Ensure that the PATH configuration specifies the full absolute path to the executable, 23 not a relative path. `argocd` allows plugins to add custom commands such as 24 `argocd my-plugin arg1 arg2 --flag1` by executing a `argocd-my-plugin` binary in the PATH. 25 26 ## Limitations 27 28 1. It is currently not possible to create plugins that overwrite existing 29 `argocd` commands. For example, creating a plugin such as `argocd-version` 30 will cause the plugin to never get executed, as the existing `argocd version` 31 command will always take precedence over it. Due to this limitation, it is 32 also not possible to use plugins to add new subcommands to existing `argocd` commands. 33 For example, adding a subcommand `argocd cluster upgrade` by naming your plugin 34 `argocd-cluster` will cause the plugin to be ignored. 35 36 2. It is currently not possible to parse the global flags set by `argocd` CLI. For example, 37 if you have set any global flag value such as `--logformat` value to `text`, the plugin will 38 not parse the global flags and pass the default value to the `--logformat` flag which is `json`. 39 The flag parsing will work exactly the same way for existing `argocd` commands which means executing a 40 existing argocd command such as `argocd cluster list` will correctly parse the flag value as `text`. 41 42 ## Conditions for an `argocd` plugin 43 44 Any binary that you would want to execute as an `argocd` plugin need to satisfy the following three conditions: 45 46 1. The binary should start with `argocd-` as the prefix name. For example, 47 `argocd-demo-plugin` or `argocd-demo_plugin` is a valid binary name but not 48 `argocd_demo-plugin` or `argocd_demo_plugin`. 49 2. The binary should have executable permissions otherwise it will be ignored. 50 3. The binary should reside anywhere in the system's absolute PATH. 51 52 ## Writing `argocd` plugins 53 54 ### Naming a plugin 55 56 An Argo CD plugin’s filename must start with `argocd-`. The subcommands implemented 57 by the plugin are determined by the portion of the filename after the `argocd-` prefix. 58 Anything after `argocd-` will become a subcommand for `argocd`. 59 60 For example, A plugin named `argocd-demo-plugin` is invoked when the user types: 61 ```bash 62 argocd demo-plugin [args] [flags] 63 ``` 64 65 The `argocd` CLI determines which plugin to invoke based on the subcommands provided. 66 67 For example, executing the following command: 68 ```bash 69 argocd my-custom-command [args] [flags] 70 ``` 71 will lead to the execution of plugin named `argocd-my-custom-command` if it is present in the PATH. 72 73 ### Writing a plugin 74 75 A plugin can be written in any programming language or script that allows you to write command-line commands. 76 77 A plugin determines which command path it wishes to implement based on its name. 78 79 For example, If a binary named `argocd-demo-plugin` is available in your system's absolute PATH, and the user runs the following command: 80 81 ```bash 82 argocd demo-plugin subcommand1 --flag=true 83 ``` 84 85 Argo CD will translate and execute the corresponding plugin with the following command: 86 87 ```bash 88 argocd-demo-plugin subcommand1 --flag=true 89 ``` 90 91 Similarly, if a plugin named `argocd-demo-demo-plugin` is found in the absolute PATH, and the user invokes: 92 93 ```bash 94 argocd demo-demo-plugin subcommand2 subcommand3 --flag=true 95 ``` 96 97 Argo CD will execute the plugin as: 98 99 ```bash 100 argocd-demo-demo-plugin subcommand2 subcommand3 --flag=true 101 ``` 102 103 ### Example plugin 104 ```bash 105 #!/bin/bash 106 107 # Check if the argocd CLI is installed 108 if ! command -v argocd &> /dev/null; then 109 echo "Error: Argo CD CLI (argocd) is not installed. Please install it first." 110 exit 1 111 fi 112 113 if [[ "$1" == "version" ]] 114 then 115 echo "displaying argocd version..." 116 argocd version 117 exit 0 118 fi 119 120 121 echo "I am a plugin named argocd-foo" 122 ``` 123 124 ### Using a plugin 125 126 To use a plugin, make the plugin executable: 127 ```bash 128 sudo chmod +x ./argocd-foo 129 ``` 130 131 and place it anywhere in your `PATH`: 132 ```bash 133 sudo mv ./argocd-foo /usr/local/bin 134 ``` 135 136 You may now invoke your plugin as a argocd command: 137 ```bash 138 argocd foo 139 ``` 140 141 This would give the following output 142 ```bash 143 I am a plugin named argocd-foo 144 ``` 145 146 All args and flags are passed as-is to the executable: 147 ```bash 148 argocd foo version 149 ``` 150 151 This would give the following output 152 ```bash 153 DEBU[0000] command does not exist, looking for a plugin... 154 displaying argocd version... 155 2025/01/16 13:24:36 maxprocs: Leaving GOMAXPROCS=16: CPU quota undefined 156 argocd: v2.13.0-rc2+0f083c9 157 BuildDate: 2024-09-20T11:59:25Z 158 GitCommit: 0f083c9e58638fc292cf064e294a1aa53caa5630 159 GitTreeState: clean 160 GoVersion: go1.22.7 161 Compiler: gc 162 Platform: linux/amd64 163 argocd-server: v2.13.0-rc2+0f083c9 164 BuildDate: 2024-09-20T11:59:25Z 165 GitCommit: 0f083c9e58638fc292cf064e294a1aa53caa5630 166 GitTreeState: clean 167 GoVersion: go1.22.7 168 Compiler: gc 169 Platform: linux/amd64 170 Kustomize Version: v5.4.3 2024-07-19T16:40:33Z 171 Helm Version: v3.15.2+g1a500d5 172 Kubectl Version: v0.31.0 173 Jsonnet Version: v0.20.0 174 ``` 175 176 ## Distributing `argocd` plugins 177 178 If you’ve developed an Argo CD plugin for others to use, 179 you should carefully consider how to package, distribute, and 180 deliver updates to ensure a smooth installation and upgrade process 181 for your users. 182 183 ### Native / platform specific package management 184 185 You can distribute your plugin using traditional package managers, 186 such as `apt` or `yum` for Linux, `Chocolatey` for Windows, and `Homebrew` for macOS. 187 These package managers are well-suited for distributing plugins as they can 188 place executables directly into the user's PATH, making them easily accessible. 189 190 However, as a plugin author, choosing this approach comes with the responsibility of 191 maintaining and updating the plugin's distribution packages across multiple platforms 192 for every release. This includes testing for compatibility, ensuring timely updates, 193 and managing versioning to provide a seamless experience for your users. 194 195 ### Source code 196 197 You can publish the source code of your plugin, for example, 198 in a Git repository. This allows users to access and inspect 199 the code directly. Users who want to install the plugin will need 200 to fetch the code, set up a suitable build environment (if the plugin requires compiling), 201 and manually deploy it.