Generate a Declartive and Continually Up to Date List of the Api Surface in the Windows Sdk

Jenkins introduced a Declarative pipeline which allows one to break the whole process into different stages/jobs which trigger each other in a sequence. The key feature is Pipeline-as-a-code which allows us to define the entire pipeline flow as code in a text file.

JenkinsFile

A text file that contains the entire workflow as code that can be checked into SCM/VCS just like the rest of the code and triggers the pipeline if present otherwise the pipeline will be created.

Go to the application and create a new file (right-click on the project -> New -> File) at the same level as the POM file, give the name as JenkinsfilePaste the code given below in that.

pipeline { agent any stages { stage('Build') { steps
{ bat 'mvn clean package' } } stage('Deploy') { steps
{ bat 'mvn deploy -DmuleDeploy' } } } }

The script starts with a pipeline tag that contains the entire process of the workflow. The agent specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed, it must be defined at the top level. Agents can be defined at stage level also. The next block, stages contain all the work that needs to be carried out. It specifies one or more stage which is executed sequentially.

Each stageperforms a specific task. The first stage "Build" simply builds the project and creates a JAR file that is deployed to the Cloudhub by the second stage.
Use sh for shell scripts and bat for Windows Batch scripts
Check-in the file along with the rest of the code.

Creating the Pipeline

Go to Jenkins -> New item. create a pipeline
Select Pipeline and click OK.
On the next screen provide Description (optional). Select GitHub hook trigger for GITScm polling under Build Triggers and configure webhook in Github as shown in here.

In the Pipeline section, select Pipeline script from SCM, select the SCM (selected Git here) and provide the repository URL and credentials. Specify the script path, by default the path is for the root level, change if Jenkinsfile is not at the root level. pipeline definition Click Save.
Trigger the build. demo-pipeline

Pipelines can be configured for human input or approval before continuing further.

SCM

The pipeline will wait for an unspecified amount of time for user input. This can be changed by introducing a timeout in the step.

The pipeline will wait for 100 seconds before aborting the pipeline if no input is provided.

proceed or deploy

If the timeout expires, the pipeline status will be marked as Aborted.

checkout SCM

To mark the build as Success even if the timeout expires or the user chooses to abort, add try/catch to suppress the error.

The script block defines a variable proceed, then inside try block it sets the timeout for 100 seconds and asks for the input and if the timeout expires or pipeline is aborted it will go the catch block, set proceed to false and come out. If input provided is Proceed, the pipeline will continue as normal otherwise it will stop but the build status will be marked as Success.

324m

Post Conditions

Pipelines can define one or more steps to be run after the pipeline's or stage's completion using postblock. This is useful to run cleanup processes, send notifications depending on the stage's or pipeline's status. The condition blocks run in the following order

Condition Description
always Run the enclosed step(s) regardless of pipeline's or stage's completion status
changed Run the enclosed step(s) only when the pipeline's or stage's completion status is different than the previous run.
fixed Run the enclosed step(s) only when the pipeline's or stage's completion status is success and the previous run failed or was unstable.
regression Run the enclosed step(s) only when the pipeline's or stage's completion status is a failure, aborted or unstable, and the previous run was successful.
aborted Run the enclosed step(s) only when the pipeline's or stage's completion status is aborted.
failure Run the enclosed step(s) only when the pipeline's or stage's completion status is failed.
success Run the enclosed step(s) only when the pipeline's or stage's completion status is a success.
unstable Run the enclosed step(s) only when the pipeline's or stage's completion status is unstable.
unsuccessful Run the enclosed step(s) only when the pipeline's or stage's completion status is not a success.
cleanup Run the enclosed step(s) after all the postconditions have been evaluated.

Add the below code after stagesblock.

 Check in the code, the build will be triggered automatically. Cancel the pipeline run, go to console logs for the build.

pipeline

Since the previous build was a success and this one is Aborted, postconditions always, changed, regression, aborted, unsuccessful, and cleanup were executed.
Trigger the build again and let the pipeline finish, timeout or abort it by passing Abort when asked for input, the pipeline status will be Success as we have configured it for the same using try-catch

continue to deploy

The declarative pipeline has many other directives like parallel executions, triggers when conditions, and more. For further reading, refer here

Thanks for reading.

leeweandstaid1971.blogspot.com

Source: https://dzone.com/articles/how-to-create-jenkins-declarative-pipeline

0 Response to "Generate a Declartive and Continually Up to Date List of the Api Surface in the Windows Sdk"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel