'Build a jar file from project folder in a specific location of git repository using azure devops

I am having a git repository for my project with a structure as shown below. enter image description here enter image description here The structuring is based on the source, all the codes, scripts related to a source is kept under the respective source folder. The scripts and code consists of sql, scala, pyhton...all kind of files used for that source.

Now for one of the source, I have to create a jar file.

  1. For that I have created a project in IntelliJ using sbt build and create jar file.
  2. Create a folder under respective source and copy the entire project into the created folder as below.

enter image description here enter image description here

I have to use azure devops for creating jar file and store it in a dbfs location. There are two things i have to get clarity on.

  1. How to create a jar file from this location of repository using sbt build file from devops? I tried with devOps, but could not see any agent job to create jar file from sbt file. enter image description here
  2. If I could convert this sbt file into pom.xml, how could i create a jar file from this location of repository using devops?


Solution 1:[1]

You should have sbt available on Ubuntu host agent. Here you have an example YAML code:

name: sbt

trigger:
- master

variables:
  sbtFileDirectory: '<pass your folder where sbt file is>'
pool:
  vmImage: 'ubuntu-latest'
steps:
- script: sbt clean
  displayName: 'Running $ sbt clean'
  workingDirectory: $(sbtFileDirectory)
- script: sbt update
  displayName: 'Running $ sbt update'
  workingDirectory: $(sbtFileDirectory)
- script: sbt compile
  displayName: 'Running $ sbt compile'
  workingDirectory: $(sbtFileDirectory)
- script: sbt test
  displayName: 'Running $ sbt test'
  workingDirectory: $(sbtFileDirectory)

With classic/release pipelines it would be similar:

enter image description here

You can also monitor this topic on developer community - Scala and SBT builder

Solution 2:[2]

According to your description, you want to add build output (from Azure DevOps) into Source Control (GitHub). It's not recommended to update source control from a build, If you have special reason to do this, you can run git commands in the Powershell Task to do the commit and push. Check the answer in this case: Send specific files from Azure DevOps pipeline to Github

    #Clone repo to your workspace
    git clone https://github.com/repo
    
    #assuming master is your branch
    git checkout master
    
    #Refresh repo if is already in your workspace
    git pull -q 2>&1 | Write-Host
    
    #Copy file to the worspace
    XCOPY "File current location" "Git workspace location"
    
    #Add files to the local repo
    git add -A
    
    #Commits the file to local repo:
    git commit -m "Files commited."
    
    #Pushes the changes to Git repo
    git -c http.extraheader='AUTHORIZATION: bearer $env:System_AccessToken' push -q -f

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Cece Dong - MSFT