pipeline {
  agent {
    docker { image 'mcr.microsoft.com/dotnet/sdk:6.0'}
  }

  environment {
    PWDNVERSION = "0.1.0"
    // home is required to make dotnet work as if undived / is used which is not accessible
    HOME = "${env.WORKSPACE}"
  }

  stages {
    stage('cleaning workspace') {
      steps {
        sh "rm -rf ${env.WORKSPACE}/publish"
      }
    }

    stage('nuget restore') {
      steps {
        sh "dotnet restore ${env.WORKSPACE}/src/PiwigoDotnet.sln"
      }
    }

    stage('test') {
      steps {
        sh "dotnet test ${env.WORKSPACE}/src/PiwigoDotnet.sln --no-restore"
      }
    }

    stage('packing') {
      steps {
        sh "dotnet pack ${env.WORKSPACE}/src/PiwigoDotnet.sln --no-restore -c Release -o ${env.WORKSPACE}/publish -p:Version=${env.PWDNVERSION}.${env.BUILD_NUMBER}"
      }
    }

  }

  post {
    always {
      archiveArtifacts artifacts: "publish/*.nupkg", onlyIfSuccessful: true
    }
  }
}