Search code examples
androidjenkinsjenkins-groovycicd

Jenkins zip debug and release APKs and want to do archiveArtifacts


in my project we have 2 build variants (assume) paidA & paidB. assemble the app will generate 4 apks which are (paidA debug and release) and (paidB Debug and release). I need to artifact all these four apks. I tried with the following code but it fails

sh "zip -r builds.zip . -i builds"
sh "cd ${env.WORKSPACE}"
echo "${env.WORKSPACE}"
archiveArtifacts artifacts: "builds.zip", onlyIfSuccessful: true

Kindly advice a bit to get rid off this.


Solution

  • Here is my working solution. Kindly make sure the path as per your project.

     stage('Artifact') {
      steps {
       script {
         sh "mkdir -p ${env.WORKSPACE}/builds"
                
         sh "cp app/build/outputs/apk/*/*/*.apk ${env.WORKSPACE}/builds"
    
         sh "cd ${env.WORKSPACE}/builds"
    
         zip zipFile: 'apks.zip', archive: false, dir: 
         "${env.WORKSPACE}/builds"
                
         archiveArtifacts artifacts: '${env.WORKSPACE}/builds, apks.zip', 
          onlyIfSuccessful: true
       }
      }
    }