Invoking a pipeline from another pipeline using scripted jenkinsfile - jenkins

I am using the following snippet to invoke a pipeline1 from pipeline2 both the pipelines have their own Jenkins file in their respective git repo
stage
{
build job:'../pipeline1Repo/master',parameters:[[$class:'StringParameterValue',name:'USER', value:'user'],[$class:'StringParameterValue',name:'PASSWORD', value:'password']],wait:true
}
The repo location in git for pipelines are:
pipeline1 repo - https://github.company-domain.com/main/pipeline1-repo
pipeline2 repo - https://github.company-domain.com/main/pipeline2-repo
when I am running the job I am getting following error:
build
job:'../pipeline1Repo/master',parameters:[[$class:'StringParameterValue',name:'USER',
value:'user'],[$class:'StringParameterValue',name:'PASSWORD',
value:'password']],wait:true
Note- I don't have the access to check the installed plugins I am assuming is this can be due to pipeline plugin is not installed and if so is there another way to do so without using a plugin

The issue was the plugin as I didn't have the admin access I could not check the plugin was there or not.
After installing the pipeline plugin it got resolved

Related

No such DSL method 'rtServer' found among steps in Jenkins job for JFrog Artifactory Plugin

I am trying to run a Jenkins job to publish my war file to Artifactory.
I am using Declarative Pipeline syntax
// ... previous stages
stage('rtServer to Artifactory'){
steps {
rtServer (
id: 'Artifactory-MC',
url: 'http://my-artifactory-domain/artifactory',
credentialsId: 'credentialsID',
timeout = 100
)
}
}
... //rtUpload stages and post block
When I run the Jenkins job I get the following error:
java.lang.NoSuchMethodError: No such DSL method 'rtServer' found among steps
Declarative pipeline in Artifactory Plugin was introduced in version 3.0.0. Upgrade your plugin version if it is lower, preferably to the latest version.
As for the timeout setting, this is currently bugged. This jira issue tracks the fix. The timeout has a default value of 300 if not explicitly set.

How do I chain Jenkins pipelines from a checked out git repo?

I want to checkout a git repo and then run its build so I tried:
sh "git clone --depth 1 -b master git#github.com:user/repo.git"
build './repo'
but that yields:
ERROR: No item named ./repo found
I've tried to use dir('repo') but apparently that errors when you run it from within docker (because kubernetes is stuck on an old version of docker that doesnt support this).
Any idea on how to run the build pipeline from the checked out repo?
The 'build' pipeline steps expect a job name, not a pipeline folder with a Jenkinsfile in its root folder.
The correct way to do this is to set the pipeline job with the Jenkinsfile, as described here ('In SCM' section), and call it by its Job name from your pipeline.
Pipelines are not built for chaining unless you use shared libraries where you put the Pipeline code in a Groovy class or as a step, but that it is a subject for a full article.

Jenkins pipeline run gradle tasks within sshagent

I'm creating a jenkins pipeline which utilizes a build.gradle script to build the project.
One of the first things gradle does is check out some git repos, I need to run this with ssh, so I thought I could wrap the code in sshagent like this:
sshagent(['c6f7cd1b-9bb3-4b33-9db0-cbd1f62cd0ba']){
sh 'git clone git#Repo.git'
}
the Id is mapped to a global jenkins credential with the private key in it, I also use it in another pipeline to tag a repo and push it to master, using the same credentialId.
However I get following output when trying to run the pipeline:
FATAL: [ssh-agent] Could not find specified credentials
I have no idea why I get this, when I'm using a copy paste from the other pipeline.
Anyone who can point me towards the right direction?
Thx

Pushing to GitLab repo does not trigger the Jenkins build

gitlab plugin Version: 1.4.2
jenkins Version: 2.7.4
gitlab Version: GitLab Community Edition 8.11.4
I have followed the plugin documentation and setup the webhook accordingly
(https://github.com/jenkinsci/gitlab-plugin).
Added gitlab repo to the jenkins job, the connection test succeeds.
Building the jenkins job manually also succeeds (The code is fetched
from the repo correctly so no issues there)
Added the webhook for jenkins. Testing the webhook also succeeds
(returns HTTP200). But on the jenkins side. nothing happens as a
result of the test even after it was performed after a change to the
repo (the jenkins log and gitlab plugin log show no activity)
When I try to test the whole setup. I make a new push to the gitlab
repo to see if it triggers a new build on jenkins. But nothing
happens. Can anybody help me out with this? I am not sure what is
wrong here as both the test hook and test gitlab connection show
success.
Thankyou in advance.
Naveed
In Jenkins you install and configure (global and job) Gitlab Hook Plugin
in your webhook can you make this :
URL : http://your-jenkins-server/gitlab/notify_commit or http://your-jenkins-server/gitlab/build_now.
Trigger : you check Push Events
and try again
To trigger a specific job the URL is:
http://your-jenkins-server/gitlab/build_now/job_name
job_name is the name of the job created in jenkins
I followed the instructions here and everything worked quite well: https://github.com/jenkinsci/gitlab-plugin/wiki/Setup-Example. It is possible to give back the results of the jenkins job to GitLab pipelines.
You can also push back the results using the jenkins pipeline:
node {
gitlabBuilds(builds: ['Build', 'Test', 'QA']) {
stage('Build') {
gitlabCommitStatus(name: 'Build') {
sh "your execution"
}
}
// The rest of the stages here...
}
}

Jenkins Build Flow AND Build Pipeline plugins

Will the Build Pipeline plugin still show the sequence of jobs properly if the jobs are run using Build Flow (including a repeated job)?
Here is pseudocode for our build flow:
build("Package")
build("Deploy", destination: "http://test") // deploy to our test environment
build("IntegrationTests", target: "http://test") // run automated tests
build("Deploy", destination: "http://stage") // deploy to stage
Package will pull code from source control, compile it, and store it as an artifact
Deploy will copy artifacts from the upstream Package job then copy it to the URL provided in the destination parameter
IntegrationTests will run a suite of integration tests against the URL provided in the destination parameter.
Will the Build Pipeline plugin show this pipeline as 4 steps even though the Deploy job is repeated?
Package => Deploy (test) => IntegrationTests => Deploy (stage)
The new solution, which is being adopted with Jenkins 2.0, is the Pipeline plugin. Also, CloudBees open-sourced their Pipeline Stage View plugin which provides a visualization to the Pipeline plugin.

Resources