Jenkins-All

 

 https://www.youtube.com/watch?v=7KCS70sCoK0&t=843s


https://plugins.jenkins.io/



-------------------------------------------------------------------------------------------------------------------------------



Post Job -- some automated script such as sending an email etc on the status of the built whether it is successful or not.


Define conditional run of the steps

for instance, you want to run the test in development branch build .

The current / active branch name in the build is always available in the jenkins file through and environmental that jenkins provides it .

BRANCH_NAME /OR env.BRANCH_NAME 

check if this is dev branch



This part of the buuild will only execute if the current branch is dev.



If you only want to build your application when there are code changes.

if branch name and code changes are true


CODE_CHANGES is the variable that you define yourself globally like below.


getGitChanges()  -- This would be a groovy script to check if there is any changes made.

Environmental Variables in Jenkinsfile :

How do you know what variables are available from jenkins.



To bind the credentials from Jenkins to your jenkinsfile

credentials function binds the credentials from jenkins to your environment variables. As a parametere in the quote it takes the is parameter of the jenkins credentials.

This comes as a plugin -- You may need to install credentials binding plugin in jenkins. to use this. This makes it possible to use Jenkins credentials in the jenkins file . 

Parameter it takes is the id reference of the credentials.


The below is while you define it globally.


Lets say we only need this environment variable in a paricular stage and not globally. But on a particular stage.

Use the withCredentials





After which
 
the below will take the username and store it USER variable and password in PWD



Now you can use the Usename and Password in combination with any shell commands. Lets say the shell command pushed the new build into a Artifact Repository and the Credentials for that are these .

You need two Plugins for this .

1. Credential Plugin :


2. Credentials Binding  :


Tools Attribute for build tools :

Tools attribute provides you with built tools for your projects. If you have a front-end backup application you will have some build toold configured for that such as

1. Maven
2. Gradle

For example in the build stage you may run something like maven install.

One way to have this is is using tools attribute.

There are three tools that Jenkins support - Gradle / Maven and JDK

and next you need to provide the name of the tool. that needs to be pre-installed or pre-configured in jenkins.

Manage Plugins  > Global Tools Configuration

This name is what you need to provide in your jenkins file.




The tools has to pre-configured or pre-installed in Jenkins. May be you have some external configuration that you have to provide through your build to change some behaviour .

You have to deploy the build in the staging server and you want to deploy a particular version in the staging environment. May be you want to choice which version of the application you want to deploy.

May be you want to provide some external behaviour to your tool to change the behaviour.



If you want to skip some stages you may use the below.



or you can even leave it with out == true

when {

   expression {

        params.executeTests 

    }

}


Using external script in Jenkins : 

very soon your jenkins file may get loaded external script with jenkins script or with gradle script. it is good to clear up your jenkins script into their own file.










Comments

Popular posts from this blog

JENKINS - Build In Variables