简体   繁体   English

如何将参数传递给詹金斯

[英]How to pass parameter to Jenkins

I am able to trigger a new Jenkins build every time code is committed into GitHub. 每当代码提交到GitHub时,我就能触发一个新的Jenkins构建。

Example of a Jenkinsfile in GitHub: GitHub中的Jenkinsfile的示例:

node ('aws-slaves') {
    stage ('Gate 1: Checkout Code') {
        wrap([$class: 'TimestamperBuildWrapper']) {
            echo "Deleting dir"
            deleteDir()
        }
    }
}

How do I pass parameter from another GitHub file (that is in the same repo) and print parameter value? 如何从另一个GitHub文件(位于同一存储库中)传递参数并打印参数值?

I was exploring different ways to do it and here is one way: 我正在探索实现此目标的不同方法,这是一种方法:

Inside a Jenkins file - you can set to execute a 'shell' script. 在Jenkins文件中-您可以设置执行“ shell”脚本。 One of the commands from a shell script can be 'curl'. Shell脚本中的命令之一可以是“ curl”。 With a curl command - value from a GitHub repository (from a specific file in it) can be printed to a screen, it can be saved into a file or stored in temporary variable. 使用curl命令-可以将GitHub存储库中的值(来自其中的特定文件)打印到屏幕上,可以将其保存到文件中或存储在临时变量中。 In that way - build can be parametrized via github by storing specific values in separate files (in github repository) and content of a file can be read during a build. 这样-通过将特定的值存储在单独的文件中(在github存储库中),可以通过github对构建进行参数化,并且可以在构建期间读取文件的内容。

Another way is to use a jenkins hook inside github which will trigger a build every time code is committed. 另一种方法是在github中使用jenkins挂钩,每次提交代码时都会触发构建。 During that build - whole github repository (where code is committed) will be fetched and stored inside temporary directory on a server where Jenkins is running. 在构建期间-将获取整个github存储库(提交代码的地方)并将其存储在运行Jenkins的服务器上的临时目录中。 From that (local) folder - any file from a (cloned) repository can be read into a variable and in that way parameterization can be achieved as well. 从该(本地)文件夹中-来自(克隆的)存储库的任何文件都可以读入变量,并且也可以实现参数化。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM