Jenkins 2 Pipeline workspaces xxx#script - jenkins

I am new to Jenkins 2 and pipeline feature, and I am setting up a project to use the Jenkinsfile for pipeline.
I can see there are 3 workspace created:
project-xxxxx
project-xxxxx#script
project-xxxxx#tmp
When I run tox in pipeline, it complains about no tox.ini found, I suspect it's in side folder project-xxxxx which is empty, but the project files are inside project-xxxxx#script
Should I use checkout scm to populate the workspace with project files? Or am I suppose to use the project files in project-xxxxx#script and how do I do it properly?
Can someone please explain to me how those 3 folders work together?

You should not have to worry about the workspace in a pipeline. You start the build, you get a workspace and anything you checkout out or copy into it should be there.
How do you start the pipeline? Inline script, from scm or via a Multi-Branch or similar job type?
How are you getting files into your workspace?

Related

Ho do I restart the jenkins pipeline with an updated JenkinsFile

I have a Jenkins project with a declarative pipeline defined in a JenkinsFile stored in a SCM. I use the "Pipeline script from SCM" option.
Sometimes if something fails I do a quick fix in the jenkins workspace and rerun the pipeline starting at a specific stage. This is working nicely.
There are cases in which I need to update the JenkinsFile and then do a 'restart at stage' with the updated Jenkins file. However, I can't find the JenkinsFile anywhere in the workspace folder. I need to know the location so I can do a quick fix and then restart the pipeline. Where is the JenkinsFile located?
See "Replay" Pipeline Runs with Modifications:
The "Replay" feature allows for quick modifications and execution of an existing Pipeline without changing the Pipeline configuration or creating a new commit.

Change working directory during Jenkins build (not gradle, not maven)

Can I change the working directory during a Jenkins job for all successive steps?
My job's first step checks out a git project. Unfortunately this project has a mix of technologies; it's not a java/maven project (so the trick of 'mvn -f subdir/pom.xml' doesn't apply) nor is it a gradle project. So I'd like to change to a subdirectory of the checked-out project and start running Jenkins plugins, like invoking shell scripts, like running tox to test python code, like running docker to build images, etc.
Maybe Jenkins wants every step to begin in $WORKSPACE, and allowing a directory change during the job would break some vital assumptions?
I know this has been asked before. Similar questions but answers specific to maven:
Jenkins Maven Build -> Change Directory and
Jenkins: How To Build multiple top-level projects from a git repository?
Similar question but answer specific to gradle:
Change directory during a build job on jenkins
You can separate out job based on sub folders and use filter to checkout in you SCM configuration so only sub folder that you want for that job will get cloned in your workspace. As your first step of your build use batch/shell command to move all file from sub folder to workspace. and then run all the steps that you want.

Jenkins DSL copy workspace to another job

I´m using Jenkins DSL, and I need to copy the workspace from one job to another, I´ve been looking for an API to do that without success.
Any idea how to do that using the DSL?
Regards.
It looks like you can use the clone SCM plugin
This plugin makes it possible to archive the workspace from
builds of one project and reuse them as the SCM source for
another project.
Which is supported by job-dsl
publishCloneWorkspace(String workspaceGlob) {}
Archives files for Clone Workspace SCM source.
cloneWorkspace(String parentProject, String criteria = 'Any')
Add a SCM source which copies the workspace of another project. Valid
criteria are 'Any', 'Not Failed' and 'Successful'.

Jenkins Archive Downstream Multibranch Pipeline

I have a multibranch pipeline in Jenkins and need to pass the archive from the pipeline to a job it builds. The copy artifact plugin doesnt seem to support multibranch pipelines. It deletes my source project every time I save. Is there another plugin I can use to get the archive to get passed to the job? Or is there something I need to do to get this plugin working with multibranch pipeline?
The copy artifact plugin doesnt seem to support multibranch pipelines.
Copy Artifact does not care about multibranch. From its perspective, a branch project is simply a job that is in some folder. And it does support folders. You just need to use the correct syntax for the source job. Last I remember, it supports either relative (e.g., ../multibranch/master) or absolute (e.g., /organization/repo/master).

Jenkins config file provider plugin in a slave

I want to use a config file provided by config file provider plugin in a pipeline project.
However when I run a build step inside a slave. I get a "PermissionDenied" exception, The same runs in master however.
So question is thats the best possible way to share files between master and slaves. I may not be able to Copy to slave plugin as there doesn't seem to be pipeline support.
If you want to share files between stages or nodes you can use the stash - unstash methods. see the example here
If you want to share files between builds you can use the archive method and the Copy Artifact Plugin

Resources