如何在 Jenkins 脚本管道中设置多行参数化 cron 作业?

2024-04-09

所以这工作正常:

properties([
    //https://stackoverflow.com/questions/35370810/how-do-i-use-jenkins-pipeline-properties-step
    parameters([
        //note here that the default will be the element you have as a first choice in the array
        choice(name: 'environmentName', choices: ['PROD', 'STAGE'], description: 'Choose the environment you want to run automation tests'),
    ]),

    //explained here: https://stackoverflow.com/questions/44113834/trigger-hourly-build-from-scripted-jenkinsfile
    //recall that ANY change you do here you will need to execute the job once manually for the new cron parameter to be updated, pushing it is not enough
    //minutes, hours, day of month, month, day of week  //H is any first available (here minute) of the hour according to resources
    pipelineTriggers([
       parameterizedCron('*/2 * * * 0-4 %environmentName=STAGE')
    ]),
])        

但是,当尝试在多行中定义它时,如下所述:https://github.com/jenkinsci/parameterized-scheduler-plugin/blob/master/README.md https://github.com/jenkinsci/parameterized-scheduler-plugin/blob/master/README.md

那么这不起作用:

properties([
    //https://stackoverflow.com/questions/35370810/how-do-i-use-jenkins-pipeline-properties-step
    parameters([
        //note here that the default will be the element you have as a first choice in the array
        choice(name: 'environmentName', choices: ['PROD', 'STAGE'], description: 'Choose the environment you want to run automation tests'),
    ]),

    //explained here: https://stackoverflow.com/questions/44113834/trigger-hourly-build-from-scripted-jenkinsfile
    //recall that ANY change you do here you will need to execute the job once manually for the new cron parameter to be updated, pushing it is not enough
    //minutes, hours, day of month, month, day of week  //H is any first available (here minute) of the hour according to resources
    pipelineTriggers([
        //cron('H 23 * * 0-4') //this works with the DEFAULT parameters
        parameterizedCron { //this is documented here: https://github.com/jenkinsci/parameterized-scheduler-plugin/blob/master/README.md
            parameterizedSpecification( '''
                # leave spaces where you want them around the parameters. They'll be trimmed
                #*/2 * * * * %environmentName=STAGE;SomeOtherVariable=Pluto
                #you may repeat multiple configuration if you want
                */2 * * * 0-4 %environmentName=STAGE
            ''' )
        }
    ]),
])

执行詹金斯作业后收到的异常是这样的:

java.lang.ClassCastException: org.jenkinsci.plugins.parameterizedscheduler.ParameterizedTimerTrigger.parameterizedSpecification expects class java.lang.String but received class org.jenkinsci.plugins.workflow.cps.CpsClosure2

所以看来parameterizedSpecification发现方法正常,它只抱怨传递的参数,但传递的参数只是一个多行字符串。 这是正确的 Groovy 语法问题还是其他问题?完全不确定。我们需要你的帮助


答案可能就是这么简单:

parameterizedCron( '''
          */2 * * * 0-4 %environmentName=STAGE
          */3 * * * 0-4 %environmentName=PROD
        ''' )

这意味着您不需要包含更复杂的形式parameterizedSpecification

没有完全理解为什么这有效

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Jenkins 脚本管道中设置多行参数化 cron 作业? 的相关文章

  • 在 PHP 中使用消息队列与普通 Cron 作业之间的区别

    我们有一个基于 PHP 构建的大型 Web 应用程序 该应用程序允许安排推文和墙贴 并且有从服务器发出的预定电子邮件 我所说的 计划 是指这些 PHP 脚本计划在特定时间运行cron 大约有 7 个 PHP 文件可以完成上述工作 我一直听说
  • Jenkins 的 Gerrit 触发器找不到任何要构建的修订

    我在使用 Jenkins Gerrit 时遇到问题 这是我到目前为止得到的 Jenkins 中的 Gerrit 触发器配置似乎没问题 当我推送新的变更集时 Jenkins 构建就会启动 我用过这个 Jenkins Gerrit 触发器问题的
  • Jenkins Cron 表达式未在正确的时间安排

    All 尝试配置 jenkins 作业在每天上午 10 点触发并在 cron 下使用H 10 但 jenkins 控制台不是在上午 10 点运行 而是在上午 10 点 09 分运行 请帮助我全年每天上午 10 点跑步 update Afte
  • 在 Jenkins 中运行 MsTest 失败,CreateProcess 错误=5,访问被拒绝

    我正在从 Jenkins 运行 MsTest 作为构建步骤 但它失败了 Test c Program Files x86 Microsoft Visual Studio 14 0 Common7 IDE resultsfile TestRe
  • 在 Dockerfile 中安装节点?

    我是AWS elastic beanstalk的用户 我遇到了一些问题 我想用 less node 构建我的 CSS 文件 但我不知道在使用 jenkins 构建时如何在 dockerfile 中安装节点 这是我在 docker 中使用的安
  • 您可以使用 Jenkins Pipeline 解析 TAP 格式吗?

    我正在尝试解析 BATS 脚本的输出 https github com gaia adm docker bench test https github com gaia adm docker bench test 输出为 TAP 格式 我稍
  • 构建成功后从远程计算机上的工作区执行 Shell 脚本 (Jenkins)

    场景是 我有一个工作 A 它运行我的 ant 脚本并为我打包工件 我还使用参数化触发器插件来触发我的 作业 B 它将在远程计算机上部署我的工件 工作 A 工作正常 工作 B 也工作正常 我必须使用作业 B 执行的任务是 GIT checko
  • 使用 WGET 运行 cronjob PHP

    我尝试执行一个 cron 并每 5 分钟运行一个 url 我尝试使用 WGET 但我不想下载服务器上的文件 我只想运行它 这是我使用的 crontab 5 wget http www example com cronit php 除了 wg
  • UNIX crontab 中的日期时间格式

    我每 6 小时运行一次 cron 来备份我的数据库 我希望文件名包含按以下格式创建的日期和时间 mysqlbackup 22 5 2013 15 45 sql gz 这是我运行的命令 date date d mysqldump uusern
  • Jenkins - Xcode 构建工作协同设计失败

    下面是我的构建脚本 不使用 xcodebuild 插件 构建步骤工程 我使用所需的证书和私钥创建了一个单独的钥匙串 它们在钥匙串访问中可见 脚本中的钥匙串命令不会失败 安全列表钥匙串将这些显示为有效的钥匙串 它的表现就像解锁命令并未真正成功
  • 使用 jenkins.Creating .apk 文件生成 android 版本

    我正在使用 Jenkins 在 mac 上持续集成 android 应用程序 但是我无法使用 Jenkins 生成 apk 文件 就像我们在 iOS 应用程序中创建 ipa 一样 创建用于在 mac 上分发的 apk 文件的配置是什么 您可
  • 如何将参数从jenkins传递到selenium

    我正在使用詹金斯和硒 我需要将测试 url 从 jenkins 发送到 selenium 服务器 在常规选项卡下 詹金斯字符串参数 Name APP Default Value http localhost basecode 在构建后操作下
  • 在 Cloudbees Jenkins 文件夹中设置环境变量

    在我重新安装 Jenkins 和 Cloudbees Free Enterprise 插件后 Jenkins 文件夹中设置的环境变量停止工作并从配置 UI 中消失 但是 它仍然存在于文件系统上的 config xml 中 如下所示
  • SSHKit::Runner::ExecuteError:以 root@co 身份执行时出现异常:Jenkins Job 的 shell 脚本中的用户 root@ 身份验证失败

    我正在尝试从 Jenkins Job 运行 cap 部署命令 它不断抛出以下错误 我也在部署服务器中添加了 ssh 密钥 我能够从配置 Jenkins 的服务器成功部署 但是当我运行该作业时 会引发身份验证错误 这对我来说真的很重要 有人可
  • WordPress 计划事件未在设定时间触发

    在 WordPress 中 我正在创建一个插件 用于向用户发送电子邮件 为此 我使用 WordPresscron工作 所以基本上它要做的就是每小时向用户发送电子邮件 所以我的代码看起来像这样 public function construc
  • Jenkins 管道和 java.nio.file.* 方法的问题

    我正在尝试使用 java nio file 中的方法在 Jenkins 管道中执行一些基本文件操作 无论代码存在于哪个节点块中 代码都在主节点上执行 在管道中 我已经验证了各个节点块都是正确的 它们唯一地标识了特定的节点 但是 pathEx
  • 使用功能分支时避免 Maven 存储库版本冲突

    Question 如何处理 Maven 多项目构建的功能分支 Jenkins 构建和部署这些分支 以将开发人员的构建开销降至最低 但开发和功能分支无法构建相同的 Maven 版本 否则我们将面临工件和源代码之间不匹配的风险 我们有一个脚本来
  • 将 CCtray 与 Jenkins 结合使用,同时启用安全性(使用 HTTPS)

    我将 Jenkins 服务器配置为仅使用 HTTPS 并启用安全性 我也不喜欢任何未登录的人查看仪表板 即使它是空的 在这里 我禁用了 匿名 的 读取 访问权限 到目前为止 所有这些都完全符合我的喜好 但想要通过例如向远程客户端添加一些构建
  • 如何在 Jenkins 中安排构建?

    如何安排 Jenkins 构建 使其只能在每天的特定时间进行构建 例如下午 4 点开始 0 16 1 7 我理解为 每个月周一到周日下午 0 分钟 下午 4 点 但是它每分钟都会构建 如果有任何建议 我将不胜感激 谢谢 Update 请阅读
  • Azure Functions 计时器触发器线程安全

    我想知道是否有人知道如果您在 Azure 函数上设置了 Cron 设置 如果其任务执行时间超过 5 分钟 则每 5 分钟运行一次 会发生什么情况 它备份吗 或者我应该实现一个锁定功能 以防止某些东西 例如在循环中 处理先前调用已经处理的数据

随机推荐