Share Workspace with Jobs triggered From Workflow Script

540 views Asked by At

I want to use the Workspace from my workflow Task in other tasks whom I trigger via the 'build' command. I need to make this Flexible since I want to be able to trigger those jobs from various workflows with different Workspaces, this is why I cannot provide a hardcoded workspace Path.

Here is some Code:

node {

    git branch: branchName, credentialsId: '1337', url: 'https://i-didnt-provide-this.but-this-is-working.git'  

    def buildType = 'xxx'
    def buildFlavor = 'yyy'
    def hockeyAppId = 'zzz'

    def buildTypeParam = new hudson.model.StringParameterValue('buildType', buildType)
    def buildFlavorParam = new hudson.model.StringParameterValue('buildFlavor', buildFlavor)
    def hockeyAppIdParam = new hudson.model.StringParameterValue('hockeyAppId', hockeyAppId)
    def outputApkFilenameParam = new hudson.model.StringParameterValue('fileName', '*-{buildFlavor}-{buildType}.apk')
    def proguardMappingParam = new hudson.model.StringParameterValue('mappingFile', '{buildFlavor}/{buildType}/mapping.txt')

    build job: 'android_compile', parameters: [buildTypeParam, buildFlavorParam] //This needs the same workspace
    build job: 'android_lint', parameters: [buildTypeParam, buildFlavorParam] //same here
    build job: 'android_upload_hockey', parameters: [hockeyAppIdParam, outputApkFilenameParam, proguardMappingParam] //and here
}

Thanks for Help in Advance

1

There are 1 answers

0
Jesse Glick On

Rather than trying to share a workspace, which will not work, archive any files you need from downstream jobs. They can then access those files using the Copy Artifact plugin.

In this case, if you just want to check out the same Git revision in your downstream jobs, determine its commit hash and pass that to downstream builds as a parameter. JENKINS-26100 would save you from manually running git rev-parse HEAD or the like.