Making the SBT cached artifacts local to the workspace in Jenkins - jenkins

Is there a way (like with Jenkins maven plugin) to set the .ivy2/cache dir
local to the workspace of a sbt job in Jenkins? The motivation is to be able to perform a 'clean' build each time.
If not, is there some other way I can validate that all sbt dependencies are resolved from external repositories during the build, and not from local cache?

For changing default ivy home, take a look at this SO post.
One other possible solution is to add Execute Shell step prior to Build using sbt:
rm -rf ~/.ivy2/cache

Related

How to add a script file in Jenkins job workspace remotely and run it as part of build step

Is it possible to add a file to Jenkins Job workspace and run it from build step.
The Jenkins is on a remote folder and I cannot directly access workspace as a folder structure.
Is there any way to achieve this from Jenkins dashboard?
Yes you can do that. In order to achieve that you can place your file in Git repository and then in the Jenkins job you can pull it and then you can execute it as a part of Jenkins job

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.

How to automatically copy artefacts from Jenkins job into given network drive?

I'd like the files generated by Jenkins script to be automatically copied into a given directory on the local network.
Is there a plugin or script for doing that ?
In my case it worked by using SCP in a build step "Execute shell". The remote server needs to be accessible via ssh.
If your artifacts are the result of a maven build, maybe a Nexus Repository Manager is what you are looking for. A simple mvn deploy would do the job.

how to publish npm and maven in same maven reactor build using jenkins

Is there a way to publish to both an npm and a maven repository in a Jenkins job using one Maven2 reactor build pom file? The reactor build pom file contains two modules, one is a standard jar module and the other is a pom module that uses the exec plugin to call npm script targets that build the javascript project. Jenkins is configured to publish the maven dependencies to a corporate nexus server when build succeeds.
Project Layout:
project/
pom.xml
npm-module/
pom.xml
mvn-module/
pom.xml
This works great for the mvn-module and the npm-module builds. But now the trick is publishing the npm-module. Jenkins seems to only allow one publish to nexus post-build task.
Is there a way to do this? Can anyone explain how to set up Jenkins and a reactor build pom file that publishes both npm and maven modules to nexus?
I have an answer but would love to hear other ideas.
Jenkins Setup
create pre step "execute shell" to set npm _auth and email fields
npm config set _auth authhashstring
npm config set email some#email.com
add deploy to the maven "goals and options"
clean deploy -Dmaven.test.failure.ignore=true -Dfullclean=true
add "settings file from filesystem"
config/maven-settings.xml
Note: use the deploy goal instead of the jenkins "deploy artifacts to maven" post step because it does not use maven so your npm goals won't get called.
pom.xml Setup
In npm-module/pom.xml use frontend-maven-plugin and add executions to install node/npm and for npm publish. Make sure the publish is attached to the deploy phase. The instructions were good enough. Or you can use the exec plugin to execute the npm publish command on the deploy phase.
In mvn-module/pom.xml add the distributionManagement/snapshotRepository for your snapshots repo location.
maven settings.xml Setup
We put the maven settings.xml with the username and password in the project in a config directory, like this, mvn-module/config/maven-settings.xml. This is not ideal but we can replace the username and password w/ properties that can be set from maven/jenkins, I think. Jenkins will be configured to read this file from this location.
package.json Setup
In npm-module/package.json add the publishConfig/registry entry
"publishConfig": {
"registry": "url/nexus/content/repositories/npm-snapshots/"
}
Nexus Setup
The npm-snapshots hosted repository is set to allow redeploy. This is probably not a great idea but may be good enough for ongoing new development (not for releases obviously) and I was just trying to get the stack working. I will now need to work out the kinks.
So with that caveat aside, now the jenkins build will publish both java and node modules to their respective repositories from one Jenkins job using a top-level multi-module reactor pom.

Publish to Artifactory copied from another project artifacts in Jenkins

So I got few separated jobs in Jenkins. The first one gets the project from a Git repository, builds it and produces artifacts. And another one has to copy certificates from the first job and publish them to Artifactory (tried to make it using the Artifactory plugin). But the thing is that the Artifactory plugin's available only in the Build job, there's nothing like "Generic-Artifactory integration" in second job's configuration.
Does anyone know what are the requirements for making the plugin work in the Publish job?
You can write a small shell script leveraging Artifactory REST API and execute it in your second, non-build job.
I have done a similar thing with maven and a zip file. I have deployed a zip with a build step in maven calling a deploy:deploy-file and setting my Artifactory repository in settings.xml and deploying directly on my artifactory repository.

Resources