Hello!
I want to login into appcenter from a CI in order to be able to use CodePush.
At a first glance I tried using the login command providing a user and a password but returns the following error: Error: this environment requires interactive login, do not use the --user or --password switches.
appcenter login -u $user -p $password
Then I saw that you can provide a token in order to login. But I get the following error: Error: ENOENT: no such file or directory, open '/home/travis/.appcenter-cli/tokens.json'.
$ appcenter login --token $token
appcenter-cli: v1.0.7
OS: Travis CI - Ubuntu
I have been able to debug the build and I've found that if the .appcenter-cli directory doesn't exists you can鈥檛 login and the CI build brokes. Thats because the cli is assuming that you have used the old code-push-cli.
Hello @carloscuesta and sorry for delayed response from our side.
Indeed seems that the issue could be here:
https://github.com/Microsoft/appcenter-cli/blob/552e0f7d17316aaa1fc3e7fed8908c7c6d4d65b8/src/util/token-store/index.ts#L24
We are trying to access token but if it is not here than we evidently fail.
What platform you are on?
A solution could be to check tokens.json for existence and if not create file.
If possible could you try to do something like this in appcenter-cli/src/util/token-store/index.ts:
(dont forget to import fileExistsSync and fs so)
if (os.platform() === "win32") {
store = createWinTokenStore();
} else if (os.platform() === "darwin") {
store = createOsxTokenStore();
} else {
const tokenFilePath = path.join(getProfileDir(), tokenFile);
if (!fileExistsSync(tokenFilePath)) {
fs.writeFileSync(tokenFilePath, /* create empty */ "");
}
store = createFileTokenStore(tokenFilePath);
}
and let us know if it works? (would be much appreciated if you go one step further and create a PR with fix if it works but anyway we can take care of it if needed)
I would not recommend using the login command in a CI context anyway - it sets per-user state, so if multiple jobs run on an agent under the same user identity but use different tokens the multiple logins will interfere with each other.
Instead, use the --token switch on the actual commands you want to run rather than trying to log in, for example appcenter apps list --token $token.
I've been planning to add an environment variable for the token so that you could set that in a CI environment, I think I'll bump that up in the priority list, but no promises on when it gets implemented.
In the meantime, there's obviously a bug in the fallback token store, I'll take a look.
Oh, @carloscuesta fyi the stuff you pointed out about originalProfileDir is actually there due to the product rename from mobile center to app center that we did a while back. We renamed the directory but didn't want to blow up people who had logged in using the older mobile-center-cli. So it had nothing to do with the old code-push cli.
Hi @carloscuesta , following up on this, could you take a look at @max-mironov's solution above and let us know if that works? I'll be closing this thread for now, and we'll reopen this again if you have any issue.
Most helpful comment
I would not recommend using the login command in a CI context anyway - it sets per-user state, so if multiple jobs run on an agent under the same user identity but use different tokens the multiple logins will interfere with each other.
Instead, use the
--tokenswitch on the actual commands you want to run rather than trying to log in, for exampleappcenter apps list --token $token.I've been planning to add an environment variable for the token so that you could set that in a CI environment, I think I'll bump that up in the priority list, but no promises on when it gets implemented.
In the meantime, there's obviously a bug in the fallback token store, I'll take a look.