【问题标题】:Unable to use alias of .bash_profile in Jenkins build无法在 Jenkins 构建中使用 .bash_profile 的别名
【发布时间】:2017-10-24 20:11:39
【问题描述】:

我已经在 MAC 上安装了 Jenkins,并且 我正在尝试在 jenkin 构建中使用在我的 MAC ~/.bash_profile 上创建的别名。 可能吗? 我也尝试过使用 expand_aliases 选项,但不是运气。 我正在从自定义工作区运行我的 jenkins,即 /Users/user1。

这是 jenkins 控制台的输出。`Started by user admin 在工作区 /Users/user1 中构建

[user1] $ /bin/bash -xe /var/folders/55/fxxv86j970zcdv3gs27z4flm0000gp/T/jenkins2742750483712853243.sh
+ cd /Users/user1
+ pwd
/Users/user1
+ env
+ grep -i shell
SHELL=/bin/bash
+ source /Users/user1/.bash_profile


++ alias 'l=ls -lasrt'

+ l
/var/folders/55/fxxv86j970zcdv3gs27z4flm0000gp/T/jenkins2770891577912812441.sh: line 8: l: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
`

【问题讨论】:

  • 默认情况下,别名不会在 shell 脚本中展开;为什么不直接输入ls -lasrt?可读性比脚本的简洁性更受关注。

标签: linux bash macos shell jenkins


【解决方案1】:

你犯了一个大错误。不要添加这样的引号。

alias 'l=ls -lasrt' is wrong. 

正确:这会起作用

alias l='ls -lasrt' is right
alias ll='ls -alF'
alias la='ls -A'
alias lx='ls -CF'

【讨论】:

    猜你喜欢
    • 2013-09-06
    • 2015-04-02
    • 2018-10-01
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    相关资源
    最近更新 更多