VSTS Pipelines, how to answer to a cmd prompt? - node.js

I wanted to login to Heroku cli using Visual Studio Team Services release pipelines, the cmd line to login to Heroku is:
heroku login
Executing that command, Heroku cli will prompt this:
Email:
Password:
I don't know how to automate the inputs for that prompt, I would like to write a command or bash to login every time the task is executing.
EDITED
If it was from another platform, for example Github, then how do I automate a cmd prompt?
Screenshots:
My pipeline
Results from Heroku Cli

The best way it's to provide the credentials inline, for example, if you want to clone a Git repo from GitHub:
git clone https://username:password#github.com/username/repository.git
In Heroku case is impossible because they don't support this way. you can accomplish the accomplish heroku login by edit the ~/.netrc file - find the way in the above-provided answer.
But - you can try to answer the prompt automatically in this way:
(
echo "EMAIL"
echo "PASSWORD"
) | heroku login

Related

Azure DevOps pipeline not recognizing pipeline variable in Bash script (not using a YAML file)

The Azure DevOps pipeline has this variable:
Name: pat
Value: Git repo authentication token
The pipeline has a Bash script task. It is set to filepath. Filepath is set to script.sh. script.sh begins with:
git clone https://username:$(PAT)#dev.azure.com/company/project/_git/repo-name
Errors in pipeline logs:
PAT: command not found
Cloning into 'repo-name'...
fatal: Authentication failed for 'https://dev.azure.com/healthcatalyst/CAP/_git/docs-template/'
To validate that the authentication token and repo URL are accurate, I can verify this works when run as inline code:
git clone https://username:$(pat)#dev.azure.com/company/project/_git/repo-name
script.sh file is in repo-name.
However, environment variables work. Both of the following return the accurate value within the script. Note that one has no quotes and the other does.
echo $BUILD_REPOSITORY_NAME
repo-name
echo "$BUILD_REPOSITORY_NAME"
repo-name
Based on documentation I've seen (I am having difficulty with Microsoft's docs because I am not using a YAML file), I've tried unsuccessfully:
$pat
$PAT
$(PAT)
"$(PAT)"
gitToken=<backtick - Markdown is not allowing me to show a backtick here>echo $PAT<backtick>
Does anyone know what I'm doing wrong? Thank you for any tips.
Is your PAT variable a secret variable ?
If so, then it's not directly accessible in script files
As you can see in the documentation: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#secret-variables
Unlike a normal variable, they are not automatically decrypted into environment variables for scripts. You need to explicitly map secret variables.
Example:
...
env:
MY_MAPPED_ENV_VAR: $(mySecret) # the recommended way to map to an env variable
Or if you are using the visual editor, like that:
Use System.AccessToken instead of personal PAT:
git clone https://$SYSTEM_ACCESSTOKEN#dev.azure.com/company/project/_git/repo-name
To enable $SYSTEM_ACCESSTOKEN: go to release page in ADO > Tasks > Agent job > check Allow scripts to access the OAuth token

Git push send parallel copy to test server

I search the method to copy files to "test" host when I launch the "git push" command.
git push ------- TO REPO --> REPO_SERVER
\
\_________ TO DIR --> Host_TEST
Git Version: 2.20.1
It sounds like you are trying to (re) invent CI/CD.
If you are using GitHub or GitLab as a remote server you can use Pipelines (or Actions in GitHub).
In there you can define (almost) anything you want to happen after a push, I am assuming your Host_TEST is accessible online.
In case you are running your own git server
You can implement "push to deploy" using the post-receive hook. Hooks are scripts that are placed inside .git/hooks and executed at a precise phase of a git command. you can find several example implementations in .git/hook. See here for more information: Setting up Push-to-Deploy with git
In case you don't have access to your own git server
You can use the pre-push script on your local machine, BUT THIS IS A BAD IDEA
This hooks is executed after you execute git push but before git actually pushes anything. If your script fails (i.e non-zero return code) it will not push.
Also, if your script manages to copy but then git fails to push you will end up testing code that's not in your repo.
If all this sound way too complicated
You can create a bash function that does both operations and add it to your .bashrc.
Here is an example:
push_copy() {
if git push
then
# Copy for command here: scp ...
else
echo "Failed..."
fi
}

git pull not executing through a webhook in bash script

I have a node server running on ec2 in ubuntu which should update when I push into master as I have created a hook for that in Gitab integrations.
I saw the hook working through the logs and executing every command expect simple git pull.
I have checked many similar questions which have suggestions like appending env -i to reset the GIT_DIR so that the command can execute but no luck so far.
I tried executing different commands like git status and they are executing through the hook in bash script normally.
Here is my script which is in my home folder along with the repository:
#!bin/bash
cd toTheFolder
git pull
here is the end-point which executes the script
childProcess.exec(
"bash temp.sh",
{ cwd: "/home/ubuntu/repoFolder" },
function(err, stdout, stderr) {
console.log(stdout, stderr);
if (err) {
return res.status(500).send(err);
}
res.status(200).send("OK");
}
);
The error it returns is {"killed":false,"code":1,"signal":null,"cmd":"bash temp.sh"}
Any thoughts on why simple git pull is not working would be a huge help.
-Thanks
EDIT: here is the output of stdout
git#gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Use the following command
git pull https://username:password#mygithost.com/my/repository
Remember to replace the [username:password] with your git credentials, [mygithost.com] with your git host ( gitlab, ..etc), [my/repository] with your repository url
It would not work for github anyway cause they removed the username/password authentication support.
For github please check your ssh connection between your server and github.

Beginning with Heroku. Problem with authetication

I'm noob in git/heroku etc. I work according to the tutorial https://devcenter.heroku.com/articles/getting-started-with-nodejs#deploy-the-app .
I run commands in cmd:
heroku login
cd node-js-getting-started
heroku create (runned in past)
heroku auth:token
git push heroku master
After last command possibly window show where I put username "" and password heroku token that I get.
But after, this is displayed:
C:\Users\Administrátor\node-js-getting-started>git push heroku master
git: 'credential-managerd' is not a git command. See 'git --help'.
The most similar command is
credential-manager
remote: ! WARNING:
remote: ! Do not authenticate with username and password using git.
remote: ! Run `heroku login` to update your credentials, then retry the git command.
remote: ! See documentation for details: https://devcenter.heroku.com/articles/git#http-git-authentication
fatal: Authentication failed for 'https://git.heroku.com/afternoon-fjord-61446.git/'
I'm really don't know what I should do now.
I finally solved it.
I changed my .gitconfig file from default
[credential]
helper = managerd
to
[credential]
helper = manager
and I used username "blank" instead "" (empty string) and its working.

Importing repo from gitlab.com to local gitlab instance

I've created a user on gitLab.com and created a new (currently empty) project.
I then downloaded the community edition and installed onto my local machine. I can happily navigate to http://localhost/dashboard/projects and would like to 'import' the project I created on the gitlab.com
I've followed the instructions on my local server for http://localhost/help/integration/gitlab but something is clearly not working out as I never get an option to 'login via gitlab.com' after I have restarted the gitlab app locally.
Here are some details of the setup
gitlab_rails['omniauth_providers'] = [
{
"name" => "GitLab.com Oath _ to local",
"app_id" => "from the app ID on GitLab.com",
"app_secret" => "from the app secret on GitLab.com",
"args" => { "scope" => "api" }
}
]
The app settings on the server are as follows.
Name : GitLab.com Oath _ to local
appId : crazyLongNumberID
appSecret : crazyLongSecretNumber
Callback URL :
http://localhost/import/gitlab/callback
http://localhost/users/auth/gitlab/callback
Is there anyone who could give me a gentle shove in the right direction to solve my problem.
Thanks in advance.
David
So I don't like answering my own questions, but...
so I was being a tad dopey.
the trick was to use git to create a clone of the projet that I had created on my local gitlab instance. Note that this has to be done with the http not ssh version for the project.
git clone http://localhost/davem/projectName.git
This creates a sub folder of projectName in the directory where i ran the git command.
Then add some files (such as a readme) and then commit this back to the local instance with git push
git commit -m "add README"
git push -u origin master
Then to link things over to the main gitlab.com site (assuming that you have called the project the same thing.
git remote add gitlab.com git#gitlab.com:YourUserName/projectName.git
this adds in the remote project and also gives the server an 'alias' of 'git#gitlab.com' so now we can push to this server with:
git push gitlab.com
If I have correctly understood, you can have multiple named servers to push to. eg if you have a colleague who has their own gitLab.com site you can add them as well to with something such as...
git remote add FriendsName git#gitlab.com:FriendsName/projectName.git
and now you can push to them with just
git push FriendsName
I clearly haven't tested this yet... but I'm guessing this is how it should work. To see the aliases that you have set up use
git remote -v
I'm now a happy bunny rabit, and ready to set up some more stuff elsewhere. If I'd made any bad assumptions in here, please feel free to edit accordingly.
David

Resources