简体   繁体   English

在 jenkins 中运行 python 脚本

[英]Run python script in jenkins

I want to run a python script from Jenkins using Jenkinsfile.我想使用 Jenkinsfile 从 Jenkins 运行 python 脚本。 Is there any way to run it directly from Jenkinsfile.有什么方法可以直接从 Jenkinsfile 运行它。

I found python plugin ( Click Here ) in Jenkins to run a script, but there is no proper documentation for this plugin.我在 Jenkins 中找到了 python 插件单击此处)来运行脚本,但没有此插件的适当文档。 It would be very helpful if anyone explains how to integrate this plugin with Jenkinsfile.如果有人解释如何将此插件与 Jenkinsfile 集成,那将非常有帮助。

Adds the ability to execute python scripts as build steps.添加执行 python 脚本作为构建步骤的能力。 Other than that, this plugin works pretty much like the standard shell script support除此之外,此插件的工作方式与标准 shell 脚本支持非常相似

Per the docs of the plugin.根据插件的文档。 Though I have not used this plugin through pipeline, from job perspective, you have to just provide.py script (filename and path), in a same way you provide for shell/powershell script.虽然我没有通过管道使用这个插件,但从工作的角度来看,你只需要提供 .py 脚本(文件名和路径),就像你为 shell/powershell 脚本提供的一样。

Similarly, even for python, you'll be executing the script on a node, which will be either Linux or Windows.同样,即使对于 python,您也将在节点上执行脚本,该节点将是 Linux 或 Windows。

So, it would work as below:因此,它将按如下方式工作:

stage('build') {
    steps {
        sh 'python abc.py'
    }
}

References: https://www.jenkins.io/doc/pipeline/tour/hello-world/参考文献: https://www.jenkins.io/doc/pipeline/tour/hello-world/

Lookout for "Python" block.寻找“Python”块。

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

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