Skip to content

In a JavaScript action, how do I execute a Git command and save the output to a variable? #26546

Answered by laughedelic
cagross asked this question in Actions
Discussion options

You must be logged in to vote

Check this part of the docs:

const exec = require('@actions/exec');

let myOutput = '';
let myError = '';

const options = {
listeners: {
stdout: (data: Buffer) => {
myOutput += data.toString();
},
stderr: (data: Buffer) => {
myError += data.toString();
}
}
};

await exec.exec('git', ['rev-parse', '--short', 'HEAD'], options);
console.log(myOutput);
console.log(myError);

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions Build, test, and automate your deployment pipeline with world-class CI/CD Product Feedback
2 participants