Jenkins cannot find Jenkinsfile in Multibranch Project - jenkins

I am configuring a multi-branch Jenkins pipeline using a Jenkinsfile at the root of the Project directory. Using the latest version of Jenkins 2.89.4. The build log follows:
Started by user USERNAME
Checking out teamconcert-URL Build Toolkit 4.0.4-bd-app-jboss-ci-dev into C:\Program Files (x86)\Jenkins\jobs\APP_JBoss\branches\aapp-jboss-ci-dev.su0lgd\workspace#script to read Jenkinsfile
RTC : checkout...
RTC Checkout : Source control setup
RTC Checkout : Accepting changes into workspace "Jenkins JBOSS CI" ...
Using build definition configuration.
Fetching files from repository workspace "Jenkins JBOSS CI".
RTC Checkout : Deleting fetch destination "E:\JENKINS_DATA\app-jboss-dev" before fetching ...
RTC Checkout : Fetching files to fetch destination "E:\JENKINS_DATA\app-jboss-dev" ...
RTC Checkout : Fetching Completed
ERROR: C:\Program Files (x86)\Jenkins\jobs\APP_JBoss\branches\app-jboss-ci-dev.su0lgd\workspace#script\Jenkinsfile not found
Finished: FAILURE
I do not understand what that last ERROR line means. Jenkins seems to be cloning the Jenkinsfile from source control, copying it into
C:\Program Files (x86)\Jenkins\jobs\APP_JBoss\branches\aapp-jboss-ci-dev.su0lgd\workspace and then attempt to read it back after cloning the entire repository into the build workspace at E:\JENKINS_DATA\app-jboss-dev.
Why can it not find the Jenkinsfile? I placed the Jenkinsfile at both the root and inside a script folder as well (just in case).
I am pulling from an RTC build definition.
I created a simple pipeline job as well (forget about the multi-branch setup). Jenkins is still unable to find the Jenkinsfile. (same issue).
I confirmed the repository is cloned correctly from RTC (version control system) as I can see the file in the directory and it is intact.
I edited the workspace directory and created this directory. Jenkins still wasnt able to find the file.
Jenkins is not copying anything into the C:\Program Files (x86)\Jenkins\jobs\APP_JBoss\branches\app-jboss-ci-dev.su0lgd\workspace file. No error message indicates that this step failed.
Can you please explain the dynamics of this process, I am out of ideas as to how to resolve this issue.

Related

Using Remote Repos in Jenkins

I've successfully connected to a Bitbucket repository within my Jenkins job. My issue is that I haven't been able to find any information about how to access/use the files that the repository contains. I added an "Execute Shell" step after connecting the repo, but don't know where the files the repo contains are. I tried cd'ing into /NameOfRepo/NameOfSubfolder but it says the file/directory does not exist in the console output when I run the job. Where does Jenkins store files it has gained access to that live in a remote repository? Do I need to use shell commands to clone my repo to a specific location?

Where is jenkinsfile downloaded when job fetches pipeline script from SCM

I created a Jenkinsfile and pushed it to master branch.
In Jenkins pipeline job, I selected Pipeline Script from SCM and filled all other details.
When I build this job, it runs properly as expected.
Console log says 'Obtained Jenkinsfile from git <repo url>'.
I am using windows. Jenkins has a folder .jenkins in C:\Users\<Username>.
I looked in workspace folder which is empty until Jenkinsfile started downloading the repo.
Where is Jenkins storing the Jenkinsfile it downloaded in the very first step?
The output on the console log should show the directory where the Jenkinsfile was checked out. It is usually named somthing similar to what the workspace is called, but with an #script or something on the end.

Jenkins is checking out the entire SVN repo twice

I have a Jenkins Pipeline setup, and a Jenkins file which has the below content:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Hey'
}
}
}
}
A post commit hook triggers the Jenkins build successfully, and I can see it starting from the Jenkins UI. It states that it is checking out the repo to read from the Jenkins file and it stores the checkout in the workspace#script folder on the server.
Checking out svn https://<svn_server>/svn/Test/Core into C:\Program Files (x86)\Jenkins\jobs\CI_Build\workspace#script to read JenkinsPipeline/Jenkinsfile
Checking out a fresh workspace because C:\Program Files (x86)\Jenkins\jobs\CI_Build\workspace#script doesn't exist
Cleaning local Directory .
After this is complete, I make a change to a file in the repo and the build triggers via the post commit hook happily, but then it tries to checkout the entire code base again into a folder called workspace. I would have expected that the checkout happens once and then the "use SVN update as much as possible" option would kick in and only update the changed files? Or maybe I have the wrong logic?
SVN version - 1.9.7
Jenkins version - 2.84
Jenkins has to know what is in your pipeline script before it knows if it should checkout your code. It is possible that your pipeline says not to check out the code, and you set into a subdirectory and fire off the checkout yourself. Or maybe checkout multiple repos in different places. Until Jenkins sees your Jenkinsfile, it can't know what you want. So it has to checkout the repo once to see your pipeline, then again to do the work.
With git (and maybe some versions of other repo plugins) lightweight or sparse checkouts are supported, so then it only grabs the jenkinsfile instead of the entire repo. I don't think this is a supported option in SVN yet.
Lightweight checkouts are now supported by the SVN plugin, the SVN plugin was updated in version 2.12.0 to add this feature - see https://wiki.jenkins.io/display/JENKINS/Subversion+Plugin.

How to copy the artifacts from slave to Jenkins workspace?

I'm running a jenkins job on a slave and i want to store the generated artifacts in the server.Since the job is currently running on the slave the artifacts are also created there.
I tried using post build actions --->archive the artifacts.But it throws the following build error
ERROR: No artifacts found that match the file pattern "**/*.gz". Configuration error?
ERROR: '**/*.gz' doesn't match anything: '**' exists but not '**/*.gz'
Any help in this regards is highly appreciated.
Sounds like Copy To Slave Plugin is what you need
It can copy to slave (before build) and from slave (after build)
Copy files back to master node:
To activate this plugin for a given job, simply check the Copy files back to the job's workspace on the master node checkbox in the Post-build Actions section of the job. You then get the same two fields as for the Copy files to slave node before building section (note that label in the screenshot is old):
if you want to copy artifacts from JobA to the workspace of some other Job, you can do it using the Copy Artifact Plugin which is very simple to understand.
In case you just want to archive the artifacts already in JobA, then you are already in this direction and need to check what you are missing... are you sure that the artifacts are in the current workspace?
Doron

How to copy build XMLs from Master to the Slave node in Jenkins?

I have created a Jenkins job which used to run in the master and I have the build.xml file in the master.
Now I have added a slave node and added the setting Restrict where this project can be run so that my job always runs on a particular slave.
Now my build jobs are failing and I can see:
[EnvInject] - Loading node environment variables.
Building remotely on demo_slave_inst2 (slave1) in workspace /root/slave/workspace/demo_job
FATAL: Unable to find build script at /root/slave/workspace/demo_job/autobvt.xml
Build step 'Invoke Ant' marked build as failure
Recording test results
Finished: FAILURE
This autobvt.xml file already exists in the master. So looks like I need to copy this file over to the slave node manually which does not looks like quite handy.
How I can instruct jenkins to copy this as part of the build?
Use "Copy data to Workspace" http://wiki.jenkins-ci.org/display/JENKINS/Copy+Data+To+Workspace+Plugin using which you can copy the files from master to slave and run them as a part of build process (No manual effort needed!)
I sorted the issue using the Copy to Slave plugin.

Resources