在 Jenkins 控制台输出中回显

问题描述:

我正在遵循指南如何使用 Jenkins 签署 Android apk.我已经使用 KSTOREPWD 和 KEYPWD 参数化了 Jenkins 工作.Jenkins 的工作配置(Build->Execute shell)的一部分是获取这些参数并将它们存储为环境变量:

I'm following guideline how to sign Android apk with Jenkins. I have parametrized Jenkins job with KSTOREPWD and KEYPWD. A part of Jenkins' job configuration (Build->Execute shell) is to take those parameters and store them as environment variables:

export KSTOREPWD=${KSTOREPWD}
export KEYPWD=${KEYPWD}
...
./gradlew assembleRelease

问题是当构建结束时,任何人都可以访问构建控制台输出"并查看输入的密码;该输出的一部分:

The problem is when the build is over anybody can access the build "Console Output" and see what passwords were entered; part of that output:

08:06:57 + export KSTOREPWD=secretStorePwd
08:06:57 + KSTOREPWD=secretStorePwd
08:06:57 + export KEYPWD=secretPwd
08:06:57 + KEYPWD=secretPwd

所以我想在 export 命令输出之前抑制 echo,并在 export 命令之后重新启用 echo.

So I'd like to suppress echo before output from export commands and re-enable echo after export commands.

默认情况下,Jenkins 使用 set -x 启动 Execute Shell 脚本.这会导致回显所有命令

By default, Jenkins launches Execute Shell script with set -x. This causes all commands to be echoed

您可以在任何命令之前键入 set +x 来临时覆盖该行为.当然,您需要 set -x 才能再次开始显示它们.

You can type set +x before any command to temporary override that behavior. Of course you will need set -x to start showing them again.

您可以通过将以下内容放在构建步骤的顶部来覆盖整个脚本的此行为:
#!/bin/bash +x

You can override this behaviour for the whole script by putting the following at the top of the build step:
#!/bin/bash +x