相关疑难解决方法(0)

如何正确嵌套Bash反引号

要么我错过了一些强烈反对或反对,似乎没有太多的程序员报价循环.

$ echo "hello1-`echo hello2-\`echo hello3-\`echo hello4\`\``"

hello1-hello2-hello3-echo hello4
Run Code Online (Sandbox Code Playgroud)

通缉

hello1-hello2-hello3-hello4-hello5-hello6-...
Run Code Online (Sandbox Code Playgroud)

unix bash shell quoting

82
推荐指数
4
解决办法
4万
查看次数

无法在 Jenkins 管道内运行 shell 脚本

我能够运行以下 shell 脚本,但无法从 Jenkins 管道代码运行。

尝试 1。

node('buildnode') {

def value = "Myvalue"

def key = "Mykey"

sh '''

DATA=$(printf "%-50s \"$key\"" "$value")

echo "$DATA"

'''

}
Run Code Online (Sandbox Code Playgroud)

输出:

++ printf '%-50s ' ''
+ DATA=' 
Run Code Online (Sandbox Code Playgroud)

尝试2:

试过 sh " " "

DATA=$(printf "%-50s \"$key\"" "$value")

echo "$DATA"

" " "
Run Code Online (Sandbox Code Playgroud)

输出::

美元符号后的非法字符串体字符;解决方案:要么转义文字美元符号,"\$5"要么将值表达式括起来"${5}"

有人能帮我吗?

shell jenkins jenkins-pipeline

2
推荐指数
1
解决办法
2988
查看次数

在Jenkins Pipeline的Shell脚本部分中定义变量

我试图动态定义一个变量,稍后在我的Jenkins管道的一些shell命令中使用它,并抛出异常。我什至尝试将变量从环境部分预定义为无济于事。这是被禁止的操作吗?我的其他变量myVar似乎工作正常,但是在管道中是一个常量。

pipeline {
    agent any

   environment {
     py2Ana=""
     myVar="ABCDE"
   }
    stages {
        stage('Stage1') {
            steps {
                sh """
                    echo myVar=$myVar
                    echo Find Anaconda2 Python installation...
                    py2Ana=`which -a python | grep --max-count=1 anaconda2`
                    if [[ -z "$py2Ana" ]]; then
                        echo ERROR: must have a valid Anaconda 2 distribution installed and on the PATH for this job.
                        exit 1 # terminate and indicate error
                    fi
                """
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

例外

groovy.lang.MissingPropertyException: No such property: py2Ana for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63) …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-pipeline

1
推荐指数
3
解决办法
5273
查看次数

标签 统计

jenkins ×2

jenkins-pipeline ×2

shell ×2

bash ×1

quoting ×1

unix ×1