GORO GORO - 1 month ago 31
Scala Question

Passing a jenkins build parameter to sbt plugin

I need to create a jenkins project to compile and test a scala project. There are several scala projects so the build will be parameterized and run for each project.

To process a scala project, I want to use sbt plugin and specify "Sub-directory" using build parameter "project_name".

I tried to pass the parameter using $project_name, ${project_name}, %project_name% but none of those worked. I get output as follows (for first variation):

[$project_name] $ cmd.exe /C " java -Dsbt.log.noformat=true -jar C:\.......\sbt\bin\sbt-launch.jar compile test "
The directory name is invalid
FATAL: command execution failed: Cannot run program "cmd.exe" (in directory "C:\.......\$project_name"): CreateProcess error=267, The directory name is invalid
java.io.IOException: Cannot run program "cmd.exe" (in directory "C:\.......\$project_name"): CreateProcess error=267, The directory name is invalid


If I add "Execute Windows batch command" step, I am able to pass the parameter to the script using %project_name%.

What is the right syntax?

Answer

Here is the solution that worked for me.

Instead of specifying "Sub-directory Path" of every project to build, I left it empty and defined a custom workspace for jenkins job (sbt compile) to run in.

Unlike "Sub-directory Path", environment variables in field of custom workspace are resolved to values during build process.

Each time I run the job, I shall specify a full path to a scala project.

So what I need is to get a path to project directory as job parameter (pathToProject) and use it to define a custom workspace (${pathToProject}). Checking the box "Use custom workspace" under "General -> Advanced" reveals the field "Directory".

custom workspace

As soon as my working directory set, I can run my desired sbt command using sbt plugin

sbt plugin