简体   繁体   English

Jenkins:管道步骤中的“执行系统groovy脚本”(SCM已提交)

[英]Jenkins: “Execute system groovy script” in a pipeline step (SCM committed)

Is there a way to use the Jenkins "Execute system groovy script" step from a pipeline file which is SCM commited ? 有没有办法从SCM提交的管道文件中使用Jenkins“Execute system groovy script”步骤?

If yes, how would I access the predefined variables (like build) in it ? 如果是,我将如何访问其中的预定义变量(如构建)?

If no, would I be able to replicate the functionality otherwise, using for example the Shared Library Plugin ? 如果不是,我是否能够使用例如共享库插件复制功能?

Thanks ! 谢谢 !

You can put groovy code in a pipeline in a (always-source-controlled) Jenkinsfile, like this: 您可以将groovy代码放在(始终源控制的)Jenkinsfile的管道中,如下所示:

pipeline {
  agent { label 'docker' }
  stages {
    stage ('build') {
      steps {
        script {

          // i used a script block because you can jam arbitrary groovy in here
          // without being constrained by the declarative Jenkinsfile DSL
          def awesomeVar = 'so_true'
          print "look at this: ${awesomeVar}"

          // accessing a predefined variable:
          echo "currentBuild.number: ${currentBuild.number}"
        }
      }
    }
  }
}

Produces console log: 生成控制台日志:

[Pipeline] echo
look at this: so_true
[Pipeline] echo
currentBuild.number: 84

Click on the "Pipeline Syntax" link in the left navigation of any of pipeline job to get a bunch of examples of things you can access in the "Global Variables Reference." 单击任何管道作业左侧导航中的“管道语法”链接,以获取可在“全局变量参考”中访问的一些示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins-执行系统Groovy脚本插件(构建步骤) - Jenkins - Execute system Groovy script plugin (Build step) Jenkins-执行系统Groovy脚本 - Jenkins - execute system groovy script jenkins 中执行 groovy 脚本和执行系统 ​​groovy 脚本的区别? - Difference between execute groovy script and the execute system groovy script in jenkins? 在 groovy 脚本中的 jenkins 管道步骤中触发作业 - Trigger a job within a jenkins pipeline step in groovy script 如何将Team Foundation Server SCM插件与Jenkins Pipeline groovy脚本一起使用? - How can I use the Team Foundation Server SCM plugin with a Jenkins Pipeline groovy script? Groovy 脚本在不使用管道的情况下在 jenkins 上执行多个不同的作业? - Groovy script to execute multiple different job on jenkins without using pipeline? 从 groovy 管道文件在 linux Jenkins 服务器上执行 powershell 脚本? - Execute powershell script on a linux Jenkins server from groovy pipeline file? 无法使用Jenkins Pipeline步骤中的docker命令执行Shell脚本 - Cannot execute a shell script with docker command from Jenkins Pipeline step Jenkins Groovy 脚本中的预期步骤 - Step expected in Jenkins Groovy script Jenkins掩码密码在“执行系统Groovy脚本”中使用 - Jenkins mask passwords use in “Execute system Groovy script”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM