Jenkins scripted pipeline to use different jenkins token while calling ansible playbook - jenkins

I have a jenkins pipeline which is getting called from AWS lambda. The User who triggered pipeline does not have access to execute plugin which is in jenkinsfile.
Is there a way to use different jenkins token in jenkins stage or while calling the plugin something like withcredetials.

Related

How to get information about the trigger of a gitea webhook in a Jenkinsfile?

I have a Gitea and a Jenkins server. I installed Gitea plugin in Jenkins and set-up a multibranch pipeline which itself adds a webhook to the gitea repo. That works great, but the Jenkins pipeline will not build if a new tag was added. I wanted to add another webhook to do so.
As far as I can tell there is a webhook event for creation of branches and tags.
Is there a way to get the payload of the webhook in a Jenkinsfile to find out if there was a new tag added?
The Jenkins GitLab plugin makes the webhook payload information available in the Jenkins Global Variable env, which you can print (see
How to list all `env` properties within jenkins pipeline job?)
Maybe this Gitea plugin does the same ... have you tried to print all env variables?

Loading jenkinsFile from local disk and run the Declarative pipeline on the same Agent

I am setting up a Jenkins locally without SCM.
I have several Pipelines with the same JenkinsFile but with different parameters.
I would like to centralize the JenkinsFile for all the pipelines.
I found a solution originally for a scripted pipeline:
node {
load "/path/to/local/jenkinsFile.groovy"
}
The problem here is that Jenkins needs two agents to run the previous pipeline (one for the loading node, the other to run the pipeline) and both of them won't finish before the end of the pipeline.
Since I have multiples pipelines cron triggered, at some point, all the agents are busy to load the pipeline files, but since there is no more available agent to run each pipeline, the Jenkins process is stuck and then there is a bottleneck in the job queue.
For solutions I imagine:
How can I release the agent after the load of the pipeline?
Is there a way at the first pipeline (load the jenkinsFile) to keep an agent for running the pipeline?

Define agent in Jenkinsfile

I don't have access to Global Jenkins Configuration ,
because is a shared pipeline and would like to ask you if you know a way to define an agent (Virtual machine in Azure in this case)
directly in the Jenkins Declarative or scripted pipeline

Continuous deployment branch wise using Spinnaker

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

Jenkins pipeline job not start build while trigger from 'Bitbucket server webhook to jenkins'

Jenkins simple pipeline project not start build while trigger from 'Bitbucket server webhook to jenkins' Hook from bitbucket respository.
The same thing working perfectly with Freestyle job, but only pipeline job not start building. So bitbucket webhook configuration is proper.
bitbucket plugin configuration
Below is my pipeline job configuration.
Jenkins pipeline job triggers
And the simple pipeline script which I'm using.
Jenkins pipeline job script

Resources