Continuous deployment branch wise using Spinnaker - jenkins

I'm using Jenkins multibranch pipeline for CI process and for CD using Spinnaker.
I've gone through almost all documents, support channels etc. from spinnaker for "how to create spinnaker multibranch pipeline similarly as jenkins" but didn't find anywhere.
After integrating jenkins to spinnaker, in drop down list of jenkins jobs in spinnaker pipeline configuration, it shows all multibranch jobs separately. Hence for each branch I'd need to go to spinnaker and create pipeline manually.
To solve this, I'm thinking this solution: while running jenkins multibranch pipeline job > create spinnaker pipeline(if not exist) using spin cli with required parameters(branch, version, trigger using jenkins of this running branch job etc) > and trigger the same created spinnaker pipeline after jenkins job executed.
Please advise if there is any other better way to accomplish this.
Thanks.

I am not super familiar with the multibranch plugin, but you can make this simpler by doing [ triggers ] -> [ pipeline stage calling the same pipeline ] rather than calling the entire pipeline via the spin-cli.
Alternatively, if the list of jobs generated is small or well known, you could just update the list of triggers for the same pipeline programmatically as part of your release process.
i.e, in your jenkins job
add this job to list of triggers
run rest of jenkins job
job finishes, spinnaker pipeline triggers

Related

How to decouple Jenkins CI and gitlab CI pipelines?

I've only been working with Jenkins so far. We have configured a Multibranch Pipeline job to automatically build and test software. The tasks are written in Groovy and stored as Jenkinsfile in the root directory of our git repository.
Recently, we have decided to add another mechanism to automatically generate documentation. The generation of documentation (but this could be any other task) has been realized using GitLab CI.
Both pipelines are practically independent - and both are triggered by a git commit/push. What I do not understand is: why and how is the Jenkins pipeline execution associated with the GitLab CI pipeline? In the following screenshot a new column "External" appears - representing the Jenkins pipeline job.
That's not really a big issue. But as both pipelines should be independent - the results of the runs should not influence each other. However, it seems that when the Jenkins job fails, i.e. "External", the GitLab CI pipeline also fails:
Is there a way to better decouple those pipelines, i.e. let them fail or succeed individually?
This is because the Gitlab Branch Source Plugin automatically notify Gitlab about then Jenkins pipeline status. This allow you to see the result of a build directly in Gitlab. If you want to have only the result of the Gitlab CI pipeline in Gitlab, you can disable this feature :
Additional Traits:
These traits can be selected by selecting Add in
the Behaviours section.
[...]
Skip pipeline status notifications - Disable notifying GitLab server
about the pipeline status.
[...]
So in yout Gitlab group, just go the Configure > Projects > Gitlab Group > Add and select Skip pipeline status notifications.
why and how is the Jenkins pipeline execution associated with the GitLab CI pipeline? In the following screenshot a new column "External" appears - representing the Jenkins pipeline job.
In general, "External" statuses are created using the commit build status API -- Jenkins uses this API to report the Jenkins pipeline build status to GitLab CI.
This external status for Jenkins appears in your GitLab pipeline because you have configured your Jenkins server/project to report build statuses to GitLab or you have setup a webhook integration with Jenkins in GitLab (note these may be set at the group level or by an administrator, not necessarily the project level)
To remove this from your pipeline, you should disable any existing integration configurations and setup your Jenkins project independently of any GitLab integration. e.g. using git polling to trigger jenkins builds and remove any updateGitlabCommitStatus calls in your groovy scripts / build stages.

Ephemeral Jenkins Pipeline Jobs from Github and Jenkinsfile

I have automated Jenkins master and slaves deployment and redeployment successfully.
I know how to manually create pipeline jobs and add github repos to use their Jenkinsfiles for the steps.
my issue is how can I automate the pipeline jobs addition to jenkins after its been destroyed and redeployed without having to manually create the pipeline jobs and point to Jenkinsfile each time.
I have seen this done before in a container environment with chef and docker when redeployed or updated it re-adds all the pipelines automatically again.
I want to not use the UI at all only to confirm job status progress and verify settings.
I would recommend looking at the JobDSL Plugin to create jobs, using a seed job to create them on initial Jenkins startup. The Jenkins Configuration-as-Code plugin can be used to setup any other configuration outside the jobs.

Multiple GitHub Checks with Jenkins Multibranch pipeline

I have configured Jenkins using Blue ocean multibranch pipeline and a Jenkinsfile to trigger a build when new pull request appear in a repo.
In this pipeline I have two stages that run in parallel, because they are independent tests. What I would like to achieve is to display two check results on the pull request page on Github, one for each stage.
Initially I though about creating two pipelines using two different Jenkinsfile, but it seems that multibranch plugin does not support this.
What is the correct solution to achieve this?
You can use plugin - https://github.com/jenkinsci/github-autostatus-plugin
The plugin can be configured to send commit status for each stage for jobs build from a multibranch project. For example:

Jenkins BlueOcean only to build using a single branch for build?

When I build a multibranch pipeline job using BlueOcean it looks into my repository and reads all of my Jenkinsfile for each branch. to initiates multiple build, but I only want to be able to build a job based on a certain branch. Is there a way to only build blueocean?
Thanks
I sounds like your job is a Multibranch Pipeline.
If you create a job that is just a Pipeline (rather than Multibranch Pipeline), you can specify a single specific branch to build.

Trigger Jenkins Multibranch Pipeline Scan from another job

Is it possible to trigger Scan Multibranch Pipeline Now action for a Jenkins Multibranch Pipeline from another Job? I have certain issues integrating my old version of Gitlab with Pipeline Jobs in Jenkins and came upon such a workaround.
Alternatively, would it be possible to trigger Scan Multibranch Pipeline Now with a notifyCommit web hook?
The purpose of this would be to Scan Multibranch Pipeline whenever a change occurs in the Git repo, so that new branches are detected after such a change.
Another purpose, which I am unable to achieve otherwise (except for periodic polling per branch which is plain evil to me), is to trigger build of branches affected by given changeset. I use old GitLab (7.8) which does not work with the ordinary Gitlab plugin and the Gitlab Hook plugin does not work with pipeline jobs, so my workaround would be to have an non-Pipeline Job to be triggered by Gitlab Hook plugin and this job would in turn trigger Scan Multibranch Pipeline.
Turned out that simple notifyCommit web hook did the job

Resources