Jenkins Pipeline - How to copy artifacts to remote location - jenkins

I'm currently in the process of converting a freestyle job to a pipeline and have a build step that uses the ArtifactDeployer to deploy files from one directory to a remote location.
The ArtifactDeployer plugin on my freestyle job only has couple of fields set, 'Artifacts to deploy' and 'Remote File Location'.
What's the equivalent plugin I should be using that has pipeline support?

Related

How to save jenkins builds into workspace by writing jenkins declarative pipeline

I am practicing Jenkins pipeline by reading pipeline syntax documentation, as I was going through the flow I got a question that "How to save jenkins builds into workspace by writing jenkins declarative pipeline"
All jenkins builds are saved in jobs folder inside your "Jenkins Home" directory.
Example: "jobs->jobname->builds"

Jenkins Build Multiple projects in same repository

Previously we had a single monolith in GitLab repository and we used to build project in Jenkins using Jenkinsfile.
Now we are migrating it into multiple microservices and all reside in same GitLab repository. Is it possible to create pipelines for this type of setup or do we need to have each microservice in separate repository. If it is possible please point me to appropriate resources.
Each microservice can have its own Jenkinsfile, you have to tell to the Jenkins job the path of the Jenkinsfile if it is not located at the root path.
In your pipeline configuration job choose "Pipeline script from SCM" and set the "Script Path".
To only checkout the microservice you need, you can use in the "SCM" then "Additional Behaviours" the "Check out to a sub-directory" (then if the Jenkinsfile is now at the pseudo root path, you won't need to change the default "Script Path").
Yes it is possible to create pipelines to build/test/deploy from a single repository.
Use Declarative Pipeline in Jenkins.
You can have your microservices separated in different directories in a single repo and can build them all using a single pipeline using the stages & dir() option in Jenkinsfile. We're building close to 15 components from a single pipeline and push it to it's relevant artifactory from the same job. You can build non-dependent microservice components parallely too.
Documentation --> Jenkins Pipeline,Jenkinsfile

Where to store Jenkinsfile for downstream pipeline without its own repo

I'm in the process of setting up Jenkins pipeline jobs for our build. We previously used Freestyle jobs to build each of our repos, with various extra manually triggered jobs at the packaging and deployment stages.
We have the following Pipeline setup so far:
repo A/Jenkinsfile - Pipeline A - build, runs unit tests and produces
artifact
repo B/Jenkinsfile - Pipeline B - build, runs unit tests and
produces artifact
Whenever Pipeline A or B completes I want to run Pipeline C.
Pipeline C should take the artifacts of the latest A and B pipelines, package them together as a docker image, run integration tests, deploy to staging environment.
Where should I store the Jenkinsfile for Pipeline C since it does not have it's own source repo?
To me this logically sits as a separate pipeline that is downstream from A and B so assume this belongs in a separate Jenkinsfile but then where would that go in source control. To clarify I would like to have all my pipeline files under source control.
Alternatively should I try to define the whole pipeline (including integration, etc.) in just one of the parent Pipelines, skipping the build part when it is triggered from the other pipeline? Leaving the other as a simple build. For example
Pipeline A (full pipeline)
build
unit tests
artifact
(get latest B artifact)
integration test
deploy to staging
Pipeline B (simple build that then uses full pipeline)
build
unit tests
artifact
trigger Pipeline A, skipping everything up to integration test step (potentially using when blocks on those stages that look at the build trigger?)
I can find resources on either building or triggering one pipeline from another like this: https://metamorphant.de/blog/posts/2019-03-11-jenkins-101-downstream-projects/
but no information on structuring the above kind of dependencies and pipelines in Jenkins Pipeline.
When you define a 'new item' in Jenkins and select the 'Pipeline' project type, you get a form when the Pipeline is defaulted to 'Pipeline script'.
If you have a Jenkinsfile, then you switch to use 'Pipeline script from SCM' and sets it to point to the GIT location of the Jenkinsfile, but if you leave it to be 'Pipeline script' as defaulted, you can put the content of the Pipeline inside the form, and it will be saved inside the job's config.xml file, without the need to store it in source control.

Use Jenkins Job DSL to create / modify Docker Agent Templates

On our jenkins server we are providing ~30 Docker Agent Templates for build jobs. I've successfully automated the creation of the build jobs for those images using the Jenkins Job DSL plugin. Now I'm wondering whether I could use the Job DSL plugin (or any other plugin that provides scripting) to automate the configuration of the Docker Agent Templates in the Jenkins Settings:

Build a Freestyle project using Jenkins Pipeline Job

I am trying to build a code which doesn't have a pom.xml. Also i want to deploy the same to artifactory. Is there a way to build such a project using pipeline job. I can use freestyle job for building the above project. But I was hoping if there is some way to achieve the same in pipeline job. Also I require the groovy script details for artifactory deployment of such kind of project in pipeline job. But the basic question I have is this even feasible?
UPDATE:
We have a freestyle project job in whcih which we package our freestyle code into .tar and then deploy to artifactory using Generic Artifactory Configuration.
Now I am trying to achieve the same using a pipeline job. I get the point that we can use shell script inside Groovy and can build a tar package but how to deploy the tar package to Artifactory using Pipeline job.
if you have only 1 file , you can use maven deploy option , and upload the file.
http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html

Resources