如何使用环境变量

时间:2018-02-08 11:09:57

标签: linux nexus

我正在使用nexus-cli使用Shell脚本自动执行nexus存储库清理过程,我已手动为nexus-cli配置了凭据。

$ ./nexus-cli configure
Enter Nexus Host: https://MY_HOST.com
Enter Nexus Repository Name: docker
Enter Nexus Username: USER_NAME
Enter Nexus Password: PASS

我能够列出&从存储库中删除Docker镜像,我希望使用shell脚本自动执行nexus-cli configure(如将凭据作为参数传递)的过程。

nexus-cli凭据文件:     〜/ .credentials

# Nexus Credentials
nexus_host = "https://MY_HOST.com"
nexus_username = "USER_NAME"
nexus_password = "PASS"
nexus_repository = "docker"

我怎样才能做到这一点,任何人都可以帮助我

1 个答案:

答案 0 :(得分:0)

自己编写~/.credentials文件。例如

#!/bin/bash

USER=myuser
PASS=mypass
REPO=myrepo
HOST=myhost

# protect file since it contains secrets
touch ~/.credentials && chmod 600 ~/.credentials

# update file using environment variables
cat << _EOF > ~/.credentials
# Nexus Credentials
nexus_host = "${HOST}"
nexus_username = "${USER}"
nexus_password = "${PASS}"
nexus_repository = "${REPO}"
_EOF

cat ~/.credentials
# Nexus Credentials
nexus_host = "myhost"
nexus_username = "myuser"
nexus_password = "mypass"
nexus_repository = "myrepo"