如何从命令行启动Jenkins管道?

sor*_*rin 8 jenkins jenkins-pipeline

我希望能够在Jenkins管道上执行linting,而Groovy linting似乎还不够。

我怎样才能做到这一点?

Nic*_*amy 6

如果由于某种原因您不能使用 Jenkins 服务器 linter,您可以使用 npm-groovy-lint(适用于声明性或脚本化 Jenkinsfile,以及 groovy 共享库)

https://github.com/nvuillam/npm-groovy-lint

npm install -g npm-groovy-lint

npm-groovy-lint  // in the root directory of the Jenkinsfile
Run Code Online (Sandbox Code Playgroud)

  • 这对我来说真的很有帮助。一般来说,我只是想要检查一些愚蠢的错误,而不是服务器支持所有功能。 (3认同)

kon*_*oro 5

看起来有两种用于替换管道脚本的选项,一种是通过Leader上的cli或http POST调用:

通过SSH通过CLI进行lint

# ssh (Jenkins CLI)
# JENKINS_SSHD_PORT=[sshd port on master]
# JENKINS_HOSTNAME=[Jenkins master hostname]
ssh -p $JENKINS_SSHD_PORT $JENKINS_HOSTNAME declarative-linter < Jenkinsfile
Run Code Online (Sandbox Code Playgroud)

使用curl通过HTTP POST进行lint

# curl (REST API)
# Assuming "anonymous read access" has been enabled on your Jenkins instance.
# JENKINS_URL=[root URL of Jenkins master]
# JENKINS_CRUMB is needed if your Jenkins master has CRSF protection enabled as it should
JENKINS_CRUMB=`curl "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)"`
curl -X POST -H $JENKINS_CRUMB -F "jenkinsfile=<Jenkinsfile" $JENKINS_URL/pipeline-model-converter/validate
Run Code Online (Sandbox Code Playgroud)

https://jenkins.io/doc/book/pipeline/development/#linter

  • 请注意,管道短绒仅适用于声明性管道。不支持脚本管道。 (3认同)

Ken*_*lac 5

HTTP没有碎屑。

如果您想使用HTTP而又不想使用CRUMB。只需使用-u参数添加您的用户名和密码。将<username><password>替换为用户的用户名和密码。还要检查jenkins服务器的URL是否正确。

 curl --user <username>:<password> -X POST -F "jenkinsfile=<Jenkinsfile" http://localhost:8080/pipeline-model-converter/validate
Run Code Online (Sandbox Code Playgroud)

src