「Jenkins Pipeline」- 开发工具

  CREATED BY JENKINSBOT

在Jenkins的Pipeline中,包含「内建文档」和「片段生成器」,用于帮助开发Pipeline脚本,「内建文档」和「片段生成器」与Jenkins的版本相关。

这里介绍一些其他的工具。

Blue Ocean Editor

-「Blue Ocean Pipeline Editor
Jenkins中内置了一个Pipeline的编辑器,Blue Ocean Pipeline Editor,图形化操作,所见即所得,用于创建Pipeline脚本,并能提交到SCM仓库中。

Command-line Pipeline Linter

命令行的Jenkinfile的lint工具,用于检查Pipeline是否合法有效。

使用SSH命令:

#!/bin/sh

# 现在Jenkins中执行如下操作:
# 	(1)用户中配置SSH PUBLIC KEY;
# 	(2)Manage Jenkins > Configure Global Security > SSH Server > SSHD Port > Random

curl -Lv https://JENKINS_URL/login 2>&1 | grep -i 'x-ssh-endpoint'
# X-SSH-Endpoint: localhost:53801
ssh -p $JENKINS_SSHD_PORT $JENKINS_HOSTNAME declarative-linter < Jenkinsfile
# Jenkinsfile successfully validated.

也可以使用CURL命令:

#!/bin/sh

# 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

# “Replay” Pipeline Runs with Modifications

在Jenkins中重新执行脚本。

局限性:
(1)没有保存功能。直接修改并运行后无法取回。
(2)行为可能有所不同。重新运行时,对于非多分支流水里的提交信息肯能发生了变化。

IDE Integrations

某些IDE上有相关的插件:

	Eclipse - Jenkins Editor
	VisualStudio Code - Jenkins Pipeline Linter Connector
	Atom - linter-jenkins package

详细参考各个IDE的官方文档。

# Pipeline Unit Testing Framework

Pipeline的单元测试工具,用于测试Pipeline和共享库。

相关链接

Jenkins Building Docker Image and Sending to Registry
Building your first Docker image with Jenkins 2: Guide for developers

参考文献

Jenkins/Pipeline
Jenkins/Pipeline Development Tools
Pipeline Development Tools