kg5ung
kg5ung

Reputation: 11

Jenkins Pipeline Groovy MSBuild Artifacts

I am trying to build a Jenkins pipeline for my company to pull from Gitlab, do a MSBuild, Publish Artifacts to a directory and then zip up all the artifacts to push to a repository or file share. The application is a web app.

My issue occurs when I try to implement the zip function from AntBuilder. No matter what I specify for my basedir, the job fails saying that directory is not found. My code is as follows.

#!groovy​

node('dotnet') { //select any node with a doctnet label
    stage('Checkout') {  //checkout the code from source
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Windows_Gtt', submoduleCfg: [], userRemoteConfigs: [[credentialsId: '99999999-9999-9999-99999', url:      '[email protected]:api/sharedservices.git']]])
    }
    stage('Build') {  //build steps go here
         bat 'nuget restore LandingPageSvc.sln'  //restore nuget sources
         bat "\"${tool 'MSBUILD46_64_Pipeline'}\" LandingPageSvc.sln /m /p:VisualStudioVersion=14.0"   //msbuild
    }
    // stage('NUnit Tests') {  //Unit testing steps go here
    //     bat '"C:\\Program Files (x86)\\NUnit.org\\nunit-console\\nunit3-console.exe" ./LandingPageSvc.Test/bin/Debug/LandingPageSvc.Tests.dll --result nunit-result.xml'
    // }
    stage('Packaging') {
        bat "\"${tool 'MSBUILD46_64_Pipeline'}\" LandingPageSvc\\LandingPageSvc.csproj /m /p:VisualStudioVersion=14.0;Configuration=Debug;PublishDestination=..\\Publish\\Dev /t:PublishToFileSystem"
        def ant = new AntBuilder()
        ant.zip(destfile: "test.zip", basedir: "./Publish/Dev")
    }
    stage('Publish') {
      // build nuget package
      //push nuget pcakage to artifactory

    }
}

So, everything else resolves to the workspace on the dotnet build agent just fine and I have even tried using ${WORKSPACE} in the path and it still complains.

Not sure why or what context this particular function is running under, but it appears to not be on the dotnet build agent or in the project workspace.

Appreciate any suggestions.

Upvotes: 1

Views: 4493

Answers (1)

RichardWill.Net
RichardWill.Net

Reputation: 113

Could it be that you are referencing two different file locations? In one you use ..\Publish\Dev and in the other you use ./Publish/Dev. I think the "." and the ".." are going to resolve to two different file locations. The ".." refers to the parent folder of the folder you are in whereas the "." refers to the folder you are in.

Jenkins/ProjectBasedir/Publish/Dev (.) vs Jenkins/Publish/Dev (..)

Upvotes: 1

Related Questions