0
votes

in my Mac, wget command working. How to fix this issue?

Error Message

wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip /Users/don/.jenkins/workspace/demo@tmp/durable-2702e009/script.sh: line 1: wget: command not found

Full Pipeline Script

node('master') {
    def home = sh(script: "echo $ANDROID_HOME",returnStdout: true).trim()  

        def SDKPath = "$home/Android/sdk"
        stage("Preparing SDK"){
            // Check SDK Downloaded
            def isSDKDownloaded = sh(script: "test -e sdk-tools-linux-4333796.zip && echo true || echo false",returnStdout: true).trim()
            if(isSDKDownloaded == "false"){
                // Download SDK
                sh "wget 'https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip'"
            }
            // Check if SDK is Extracted
            def isExtracted = sh(script: "test -e $SDKPath/tools && echo true || echo false",returnStdout: true).trim()
            if(isExtracted == "false"){
                sh "mkdir -p $SDKPath"
                //Unzip SDK
                sh "unzip sdk-tools-linux-4333796.zip -d $SDKPath"
            }
// Install SDK Tools
            sh "yes | $SDKPath/tools/bin/sdkmanager 'build-tools;28.0.3' 'platform-tools' 'platforms;android-27'"
sh "ls $SDKPath/licenses"
            // See installed And Available SDK
            sh "$SDKPath/tools/bin/sdkmanager --list"
            // Accept All SDK Licences
            sh "yes | $SDKPath/tools/bin/sdkmanager --licenses"
        }

def selectedBranch = SELECTED_RELEASE_BRANCH
         stage('Checkout') {
             git branch: selectedBranch, url: '[email protected]:o-apps/demo.git'
            // Remove Existing local properties
            sh 'rm local.properties ||:'
            // Write sdk.dir Path into local properties file
            sh "echo 'sdk.dir=$SDKPath' >> local.properties"
         }

         stage('Setup Tools') {
             withCredentials([file(credentialsId: 'android_keystore', variable: 'KEYFILE')]) {
                 sh "cp \$KEYFILE app/key.jks"
             }   
         }

         stage('Build Release APK') {
             sh "./gradlew clean assembleRelease"
         }

         stage('Upload to Play Store') {
            androidApkUpload googleCredentialsId: 'key', apkFilesPattern: '**/*-release.apk', trackName: 'alpha'
         }

         stage('Cleanup Credential') {
             sh "rm app/key.jks"
         }
}
1

1 Answers

3
votes

This is probably due to the $PATH environment variable which is different between your user and the user running Jenkins. Your user may be altering its $PATH by expanding it in the shell resource file (~/.bashrc, ~/.zshrc).

Not to worry, you can use the full path.

To find out the full path to wget, run this on the machine that runs the pipeline (the one labelled master):

%  which wget
/usr/local/bin/wget

(Your path may naturally be different.)

Now use the full path:

                // Download SDK
                sh "/usr/local/bin/wget 'https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip'"