命令行工具

CLI 是 Erda 为开发者提供的命令行工具,您可以通过该工具在终端设备上轻松构建 Erda 应用。

下载安装

macOS

  1. wget -O /usr/local/bin/erda-cli https://erda-release.oss-cn-hangzhou.aliyuncs.com/cli/mac/erda-1.4 && chmod +x /usr/local/bin/erda-cli

Linux

  1. wget -O /usr/bin/erda-cli https://erda-release.oss-cn-hangzhou.aliyuncs.com/cli/linux/erda-1.4 && chmod +x /usr/bin/erda-cli

使用操作

完成安装后,您可以通过 erda-cli help 命令列出所有可用的 Erda Command,再通过子命令的 help 信息查看详细用法。

  1. $ erda-cli help
  2. _/_/_/_/ _/_/_/ _/_/_/ _/_/
  3. _/ _/ _/ _/ _/ _/ _/
  4. _/_/_/ _/_/_/ _/ _/ _/_/_/_/
  5. _/ _/ _/ _/ _/ _/ _/
  6. _/_/_/_/ _/ _/ _/_/_/ _/ _/
  7. Usage:
  8. erda-cli [command]
  9. Available Commands:
  10. build Create an pipeline and run it
  11. completion generate the autocompletion script for the specified shell
  12. ext Extensions operation sets,including search, pull, push, retag
  13. help Help about any command
  14. migrate Erda MySQL Migrate
  15. status Show build status
  16. version Show dice version info
  17. Flags:
  18. -h, --help help for erda-cli
  19. --host string dice host to visit, format: <org>.<wildcard domain>, eg: https://terminus-org.app.terminus.io
  20. -p, --password string dice password to authenticate
  21. -u, --username string dice username to authenticate
  22. -V, --verbose enable verbose mode
  23. Use "erda-cli [command] --help" for more information about a command.

登录

CLI 的多数子命令需在登陆后执行,有少数命令无需登录也可执行,例如 migrate 相关命令。

登录相关参数如下:

  1. --host 指定需要登录的 Erda 平台地址,若未指定且在代码目录则通过 git remote get-url origin 获取平台地址。
  2. -u--username 指定登录用户名。
  3. -p--password 指定登录密码。

::: tip 提示

登录成功后将保存 Session,Session 过期则需重新登录。

:::

erda-cli version

  1. $ erda-cli version
  2. Version: 1.4
  3. BuildTime: 2021-11-17 01:01:59
  4. GoVersion: go version go1.15.15 linux/amd64
  5. CommitID: 02583bd49fc57841bdcb05b02486e27dd868cf00
  6. DockerImage:

erda-cli build

您可以通过 build 命令构建 Erda 上的应用。

::: tip 提示

  • 请先在 Erda 上创建应用并编写 pipeline.yml 和 erda.yml。
  • 1.5 以及上版本不推荐使用。

:::

  1. $ erda-cli build --host=https://erda.cloud -u 'YourName' -p 'YourPassword'
  2. building for branch: feature/echo-web, pipelineID: 12639533, you can view building status via `erda-cli status -i <pipelineID>`

erda-cli status

您可以通过 status 命令构建 Erda 上的应用。

::: tip 提示

1.5 以及上版本不推荐使用。

:::

  1. $ erda-cli status -i 12639533
  2. pipeline progress (currentStage/totalStages): 4/4
  3. PIPELINEID TASKID TASKNAME TASKSTATUS STARTEDAT
  4. 12639533 10169335 dice Running 2021-11-22 13:38:46

erda-cli ext

您可以通过 ext 命令罗列 Erda 上所有的 Extension。

  1. erda-cli ext --host=https://erda.cloud -u 'YourName' -p 'YourPassword'
  2. ID TYPE CATEGORY PUBLIC UPDATED_AT
  3. canal addon database true 2021-11-18 01:12:56
  4. consul addon distributed_cooperation true 2021-11-18 01:12:56
  5. terminus-elasticsearch addon search true 2021-11-18 01:13:17
  6. kafka addon message true 2021-11-18 01:12:57

erda-cli ext pull

您可以通过 ext pull 命令获取 Erda 上的 Extension。

  1. $ erda-cli ext pull --host=https://erda.cloud -u 'YourName' -p 'YourPassword' git-checkout@1.0 -o git-checkout
  2. extension pull success

参数说明如下:

  1. Flags:
  2. -o, --output string which directory to export to

erda-cli ext push

您可以通过 ext push 命令更新 Erda 上的 Extension。该操作需由平台管理员执行。

  1. $ erda-cli ext push --host=https://erda.cloud -u 'YourName' -p 'YourPassword' -d git-checkout
  2. extension git-checkout push success

参数说明如下:

  1. Flags:
  2. -a, --all override exist extension and version,must with -f
  3. -d, --dir string extension dir
  4. -f, --force override exist version
  5. -r, --registry string new registry

erda-cli migrate

您可以通过 migrate 命令管理 MySQL 数据库中的数据变更。

  1. $ erda-cli migrate -h
  2. erda-cli migrate --mysql-host localhost --mysql-username root --mysql-password my_password --database erda
  3. Usage:
  4. erda-cli migrate [flags]
  5. erda-cli migrate [command]
  6. Examples:
  7. erda-cli migrate --mysql-host localhost --mysql-username root --mysql-password my_password --database erda
  8. Available Commands:
  9. lint Erda MySQL Migration lint
  10. mkpy make a python migration script pattern
  11. record manually insert the migration record
  12. Flags:
  13. --database string [MySQL] database to use. env: ERDA_MYSQL_DATABASE
  14. --debug-sql [Migrate] print SQLs
  15. -h, --help help for migrate
  16. --lint-config string [Lint] Erda MySQL Lint config file
  17. --modules strings [Lint] the modules for migrating
  18. --mysql-host string [MySQL] connect to host. env: ERDA_MYSQL_HOST
  19. --mysql-password string [MySQL] password to use then connecting to server. env: ERDA_MYSQL_PASSWORD
  20. --mysql-port int [MySQL] port number to use for connection. env: ERDA_MYSQL_PORT (default 3306)
  21. --mysql-username string [MySQl] user for login. env: ERDA_MYSQL_USERNAME
  22. --output string [Migrate] the directory for collecting SQLs
  23. --sandbox-port int [Sandbox] sandbox expose port. env: ERDA_SANDBOX_PORT (default 3306)
  24. --skip-lint [Lint] don't do Erda MySQL Lint
  25. --skip-mig [Migrate] skip doing pre-migration and real migration
  26. --skip-pre-mig [Migrate] skip doing pre-migration
  27. --skip-sandbox [Migrate] skip doing migration in sandbox