How to trigger nightly Jenkins pipeline job using a GitHub repository - github

I have a GitHub repository which contains a Jenkinsfile (with job configuration steps). I want to trigger a Jenkins simple Pipeline (not multibranch) job every night to build a jar from this repo and deploy to Nexus.
The pipeline definition options says read Pipeline script from SCM but then I don't see any option to point to specific SCM i.e. GitHub in my case. I can write the pipeline script in the Job but that is not what I want.
How can I achieve this? Please help.

You can add a build trigger for Build periodically to the jenkins job.
This will build it on a schedule for you.
You will need to install the Git Client Plugin
Then you will get the following option:
Under it you will be able to put the location of the git repo and the credentials.

Related

Salesforce DevOps with Github, sfdx & Jenkins

I need to implement a salesforce DevOps solution using Jenkins as deployment tool, Github as version control and SFDX as cli to be used as in deployment build steps.
Can anyone list out the step by step procedure once the tool(GitHub, Jenkins, salesforce, SFDX) are ready. I understood to include SFDX script or commands in build steps in Jenkins but have few queries too:
How can I deploy the entire release branch using Jenkins to target org.
How can I deploy specific components based on package.xml to target org.
Also, anyone has SFDX script to be used as reference.
I have setup salesforce, Jenkins, GitHub & SFDX tool on windows currently.
Tried deploying a set of components to target org but was not sure whether we have to create a SFDX project separately that will be committed to GitHub and will have to convert the code to metadata item.
Expectation would be to deploy salesforce components from GitHub release branch to salesforce target or using Jenkins pipeline or job.

How to use github files in spinnaker pipeline

Does anyone know how can we download GitHub repository as a part of spinnaker pipeline.
We have few scripts which are present in Github and I want to get those scripts during spinnaker pipeline execution.
You can use the Github artifact
You can use the Script or Run Command Stage to obtain the scripts and execute them.

Automatically Build GitHub Branch on Commit

I am new to working with Jenkins pipeline. I am able to use the GitHub Plugin in Jenkins and Webhooks from GitHub to successfully build a specific branch of a repository for a free style job. I can't find documentation that documents how to setup the "Source Code Management" so that only specific branches are build based on the github webhook.
For now I can chain the pipeline job to a free style job so that I can build only specific branches. I would rather have the pipeline job configured specifically for the branch we are trying to build.
Thanks in advance for your help!
SCM Configuration for the pipeline job.
!https://i.stack.imgur.com/0NoOX.png
In order to accomplish this within a Jenkins Pipeline job, you must mark the Pipeline Definition as "Pipeline script from SCM". This will instruct Jenkins to base the pipeline execution based on a Jenkinsfile within the repository. Here, you can also instruct Jenkins which branches to build.
From there, you simply need to make sure that your GitHub pushes are triggering builds within Jenkins correctly, and that's all there is to it!
The goal of the pipeline job was to build and deploy specific branch automatically. The approach was to create a pipeline job and define the branch in the SCM configuration and enable webhooks so that the branch would automatically build when a new commit is pushed. Unfortunately the webhook SCM build for pipeline is broken or is not supported for webhooks.
We have decided to change our approach and use the multibranch pipeline job. This by default build ALL branches that have a jenkinsFile. We are filtering in the job for the specific branches we want automatically build.

Jenkins - MultiBranch Pipeline : Could not fetch branches from source

I am trying to create a Multibranch Pipeline project in Jenkins with GitHub.
In the status page of the project I have the message that says that there are no branch with the Jenkins file and not build the project, as we can see in this image:
When I scan the repository, the log shows
I configured the project with a GitHub source, as we can see in this image:
The URI of the repository,
Where in the root there is the Jenkinsfile., is:
https://github.com/AleGallagher/Prueba1
Could you help me please? I've spent many hours with this and I don't know what to do.
Thank you!
To use Multibranch pipeline it is mandatory to have Jenkinsfile in repository branch.
How it works?
The Multibranch pipeline job first scans all your repository branches and looks for Jenkinsfile, if it is able to met the criteria it will proceed by executing the Jenkinsfile code and go ahead with build, if it wont be able to find the Jenkinsfile then you will find in console that "criteria not met, jenkinsfile not found in branch".
For jenkinsfile kindly visit https://jenkins.io/doc/book/pipeline/jenkinsfile/
Recommendation:-
Choose git as an option for Branch source.
Set credentials- give preference to ssh. put privatekey as jenkins side
Make sure you have correct access to Repository, if not give access by put key of same user (ssh public-key in repository)
Let me know if issue still persists.

How to trigger a Jenkins 2.0 Pipeline job from a GitHub pull request

It looks like the GitHubPullRequestBuilder is not compatible with Jenkins v2.0 pipeline jobs.
How do you configure a pipeline job to be triggered from a GitHub pull request event?
The documentation on this topic is sparse and I cannot find any examples of this. Or is it better to create a web-hook in GitHub to trigger the pipeline job on the PR event?
I had similar issue. Here’s what worked for me
Pre-req
Jenkins ver. 2+ (I was using Jenkins 2.60)
Github (or Githhub
enterprise) account
Your github and Jenkins must be able to talk to
each other.
On Github
create a github Personal Access Token (PAT) with relevant rights.
For your repo, create a webhook with
URL as YourJenkinsURL/github-webhook/
Choose ‘Let me select individual events’ and check ‘Pull Request’
Add a Jenkinsfile to the root folder of your repo. For testing purpose you could put content as a basic hello world like below
pipeline {
agent any
stages {
stage('Test') {
steps {
echo 'Hello World ...'
}
}
}
}
On Jenkins
Install GitHub Pull Request Builder plugin. (You also need “Github” plugin but that should normally be installed as part of Jenkins ver 2+)
Jenkins – Credentials
Add github Personal Access Token (PAT) as a ‘secret text’ credential.
Add github username-password as ‘username-password’ credential.
Manage Jenkins – Configure System
Github – Github Servers : This is part of the Github plugin. Add a github server. ‘API URL’ It will default to https://api.github.com. If you are using enterprise github, replace with enterprise github url followed by /api/v3. For credential select the PAT option. Test the connection. ‘Manage Hooks’ is checked.
GitHub Pull Request Builder : for ‘GitHub Server API URL’ use same url as specified in Github Server section. Leave ‘Shared Secret’ blank. For credentials use ‘username-password’ credential. Test credentials to ensure its working. In my settings, ‘Auto-manage webhooks’ was checked.
Pipeline Job
Create a new item using ‘Pipeline’ option. Note: This is the vanilla Pipeline job, not Multibranch Pipeline.
General Section: Check ‘Github Project’ – Project URL : Enter your github repo url
Build Triggers: Check ‘GitHub Pull Request Builder’
For ‘GitHub API credentials’ select option you set for GitHub pull request builder in ‘Manage Jenkins – Configure System’ screen
For admin list: add your username
Check Use github hooks for build triggering
Pipeline:
Select ‘Pipeline Script from SCM’. Note this assumes that the root folder of your repo will contain a ‘Jenkinsfile’
SCM: Select ‘Git’
Repositories – enter repo detail. For credentials use ‘username-password’ based credentials.
Click Advanced and add refspec as +refs/pull/*:refs/remotes/origin/pr/*
Branch – should be ${sha1}
Script Path: defaulted to Jenkinsfile, leave as is.
Lightweight Checkout - Uncheck this (https://github.com/jenkinsci/ghprb-plugin/issues/507)
That’s it. You are all set. Creating a PR on master branch of your repo should now trigger your Jenkins Pipeline job
Some observations
Redelivering the webhook payload of a PR from github does not trigger the pipeline but opening a new PR or even re-opening a closed PR on github, triggers the pipeline job
In Pipeline Job Configuration, if you choose “Pipeline Script” and paste your pipeline script in there, the job doesn't trigger !!!
The flow in a nutshell can go like this:
You create your pipeline as code and save it in a file called Jenkinsfile at the root dir of your project. That code should describe how your project will get built. See here for examples: https://jenkins.io/doc/pipeline/examples/
Then you should create a new "Multibranch Pipeline Project" item in your Jenkins. You should set this up so as to scan your repo of step 1.
Now whenever you get a new PR branch opened on your step 1 repo, the branch will be checked-out and will get built according to the Jenkinsfile instructions included with it. You can set up more conditions on what gets built and when if you want to.
Notes:
"Multibranch Pipeline Project" example documentation: https://jenkins.io/doc/book/pipeline-as-code/ (scroll down to Multibranch Pipeline Projects)
Keep in mind that getting the plugin to build a PR after commending on the PR does not work. There is a discussion analyzing this here: https://github.com/jenkinsci/gitlab-plugin/issues/298 There are workarounds (also described in that discussion) but they are quite messy to set up.
The most straightforward way to use Pipeline with GitHub pull requests is to put the script into your repository under the name Jenkinsfile and then install the GitHub Branch Source plugin. Documentation
Follow the Below Steps for Triggering Jenkins Job Automatically on Pull request generated on GitHub
Create a web hook on GitHub i.e. http:///generic-
webhook-trigger/invoke
Content Type :application/json
Select Pull Request as event Now github Configuration Part is done.
Jenkins Job Configuration
Download Generic Webhook Trigger in Jenkins
Git Hub Configuration On Jenkins
Git Hub Configuration
7.Select Generic Webhook Trigger on jenkins
8.Generic Webhook Trigger Configuration on Jenkinsand follow step 9
9.After doing step 7 Jenkins job will get trigger on PullRequest
10.Step 8 required to get information from Pull request Payload
11.Branch configuration inside Generic Webhook Trigger to get Branch details from Pull Request
Thanks