-1

How to fix this error in Jenkins?

[Pipeline] { (Setup Tools)

[Pipeline] withCredentials

Masking supported pattern matches of $KEYFILE

[Pipeline] {

[Pipeline] sh

cp **** app/key.jks

cp: app/key.jks: No such file or directory

Pipeline Script

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

JKS Credential added like this,

enter image description here

Android Project

build.gradle

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {

        signingConfigs {
            release {
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
                storePassword keystoreProperties['storePassword']
            }
        }

key.properties

storePassword=123abc
keyPassword=123abc
keyAlias=key
storeFile=/Users/don/Documents/key.jks

I followed this tutorial tutorial is here

BIS Tech
  • 17,000
  • 12
  • 99
  • 148

1 Answers1

0

Do a ls, e.g.

 sh "ls" 

//This will tell you if the folder is actually there, i always double check, something i could be in the wrong folder.

Then i think, it's becuase your not setting the env variable KEYFILE To test this, try;

 sh "export KEYFILE=dave"
 sh "cp \$KEYFILE app/key.jks"

You should now get a error about unable to find dave.

  • thanks for supporting. I am very beginning for Jenkins. do you have idea what is the meaning of `app/`? – BIS Tech Feb 08 '20 at 16:33
  • this is a linux command to copy a file , sh "cp \$KEYFILE app/key.jks" What your saying is copy the $KEYFILE to the folder app, into a file call keys.jks. $KEYFILE is an environment variable, and if you don't set a value to it, it becomes "", nothing. so the cp command becomes sh "cp app/key.jks", when it should be sh "cp \nameOfFile app/key.jks" –  Feb 08 '20 at 16:35
  • I already set KEYFILE. you can see on my first image. I set `android_keystore` in credential ```credentialsId: 'android_keystore', variable: 'KEYFILE'``` – BIS Tech Feb 08 '20 at 16:39
  • that just says there's a variable called KEYFILE, maybe it's not been set, try doing a echo $KEYFILE, this will help you confirm it. –  Feb 08 '20 at 16:41
  • result is ```echo this is a ****``` echo "this is a ${KEYFILE}"; – BIS Tech Feb 08 '20 at 16:53
  • sh "cp \$KEYFILE app/key.jks" this mean copy file to app/key.jks right? Is it need to create directory? – BIS Tech Feb 08 '20 at 17:05
  • ok, seems like the file variable is ok, now try changing the cp to just sh "cp \$KEYFILE key.jks", i think it maybe that the folder doesn't exists of that you don't have write access to it. –  Feb 08 '20 at 17:11
  • hmm do a sh ls -lrat, that will tell you the permission of the folder, if your lucky, you can do a chmod on the folder to say chmod -R 777 ./ , that will give everyone write,read,execute access. It will be ok for the time being. so your jenkins file shoudl be like sh 'chmod -R 777 ./' sh 'cp $KEYFILE .\key.jks' –  Feb 08 '20 at 17:28