【问题标题】:Jenkins: Unable to create directory using the date詹金斯:无法使用日期创建目录
【发布时间】:2017-12-16 17:16:27
【问题描述】:

我想使用 jenkins 创建一个带有日期的目录。 我正在使用新的 jenkins 声明式语法。 当我按照以下作业中的描述运行构建时,它会失败。 mkdir 命令在控制台上运行得非常好。

pipeline {
agent any
stages {
    stage('Prepare') {
        steps {

            echo "Checking for the existence of a debian packages directory for this package"
            sh "mkdir -p {env.JENKINS_HOME}/workspace/debian_packages/api-config/$(date +"%d-%m-%Y")"
            }
        }
    }
}

这是我得到的错误(我尝试转义 $ 字符但仍然失败)

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
failed:
WorkflowScript: 19: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the 
value expression "${5}" @ line 19, column 17.
               sh "mkdir -p 
 {env.JENKINS_HOME}/workspace/debian_packages/api-
 config/$(date +'%d-%m-%Y')"

可能是什么问题? jenkins "sh" 不是要接受直接在控制台上发出的命令吗?

【问题讨论】:

    标签: jenkins


    【解决方案1】:

    这是我可以提出的解决方法:

    stage('Prepare') {
            steps {
                script{
                sh '(date +"%d-%m-%Y") > outFile'
                def curDate = readFile 'outFile'
                echo "The current date is ${curDate}"
                sh "mkdir -p {env.JENKINS_HOME}/workspace/${curDate}"
                }
            }
        }
    

    【讨论】:

    • 谢谢。让我试试看!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多