jenkinsfile示例_Jenkinsfile用示例解释

jenkinsfile示例

代理商 (Agent)

Let’s start with agent where certain phase will be executed. It can be the entire pipeline or certain stage. At top level agent, we set it to none so we need to set each stage what agent we want to use.

让我们从执行某些阶段的agent开始。 它可以是整个pipeline或某个stage 。 在顶级代理中,我们将其设置为none因此我们需要在每个阶段都设置要使用的代理。

Let’s discus about the kind of agent below:

让我们讨论下面的代理类型:

agent {
docker {
image 'alxibra/forstok-apigateway:0.0.1'
label 'slave'
}
}

It means we run our stage in docker environment with base image alxibra/forstok-apigateway:0.0.1 . label means which server with certain label you want to execute. we have 2 servers to run Jenkins, we label our server with master and slave .

这意味着我们使用基本映像alxibra/forstok-apigateway:0.0.1环境中运行我们的舞台。 label表示您要执行带有特定标签的服务器。 我们有2台运行Jenkins的服务器,我们用masterslave标记我们的服务器。

For more information about agent you can read the documentation about agent.

有关代理的更多信息,您可以阅读有关代理的文档。

环境 (Environment)

Nothing much we can explain here, because it is explained itself. But if you wonder where credential come from. We can go to Manage Jenkins > Security > Manage Credentials

我们在这里无能为力,因为它本身就可以解释。 但是,如果您想知道证书从何而来。 我们可以去管理詹金斯>安全>管理凭据

AWS_KEY = credentials('AWS_KEY')

什么时候 (When)

when directive is used to which condition the stage should run. the when condition below has meaning that the stage always running except in branch master

when指令用于阶段应运行的条件 下面的when条件意味着阶段始终在分支master运行

when {
not {
branch 'master'
}
}

For more information see this documentation.

有关更多信息,请参阅此文档

脚步 (Steps)

steps what is to be done to complete the stage

steps完成阶段需要做什么

steps('test') {
sh 'bundle exec rspec'
}

The script above we need to run command bundle exec rspec . We can have more than one command each steps . for current condition we just need one command.

上面的脚本我们需要运行命令bundle exec rspec 。 我们每个steps可以有多个命令。 对于当前条件,我们只需要一个命令。

平行 (Parallel)

We can run multiple stages parallelly. First we need to make parent stage , inside the stage put parallel directive. Inside parallel put how many stage s you want to.

我们可以并行运行多个阶段。 首先我们需要使父stage成为stage ,在该stage里面放parallel指令。 parallel内部放了您想要多少个stage

stage('QA'){
paralle {
stage('linter'){
.......
}
stage('test') {
........
}
}
}

for more information see this documentation

有关更多信息,请参阅此文档

发布 (Post)

post section is additional step after certain stage is done or fail. We define 2 conditions the success and failure . They both send notification to our slack the status. More about conditions in post see the documentation.

post部分是某个阶段完成或失败后的附加步骤。 我们定义了successfailure两个条件。 他们都向我们发送通知,通知我们松弛状态。 更多有关条件post看到的文档

Now I try to explain the what is Jenkinsfile is doing in the file above

现在,我尝试在上面的文件中解释Jenkinsfile在做什么

Image for post
when branch is not master
当分支不是主节点时

When branch is not master we just run linter and test parallelly without executing the build image and deploy to production .

当分支不是master linter ,我们仅运行linter并进行并行测试,而无需执行build imagedeploy to production

Image for post
when branch is master
当分支是主

Now we want to release our application, we need to deploy it to production. First we need to build the application, after building is completed now we can deploy it to production. if status deploy is success or failure, jenkins will send the status to slack.

现在我们要发布应用程序,我们需要将其部署到生产环境中。 首先,我们需要构建应用程序,构建完成后,我们可以将其部署到生产中。 如果状态部署是成功还是失败,则詹金斯会将状态发送到松弛状态。

翻译自: https://medium.com/@alxibra/jenkinsfile-explained-with-example-ba2d27850880

jenkinsfile示例

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值