How does Gitlab CI determine if a PHPUnit test pass or fails?












0















I have this basic .gitlab-ci.yml file.



image: php:7.2

before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install


tests:
script:
- vendor/bin/phpunit tests


This works just fine, it alerts me if unit tests fail or pass.



My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES! exist?










share|improve this question























  • A script returning any other exit code than 0 is treat as failed.

    – Sascha Frinken
    Jan 2 at 22:07











  • @SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just Tests: 1, Assertions: 1, Failures: 1 or OK (1 test, 1 assertion)

    – IMB
    Jan 3 at 6:33













  • php.net/manual/en/function.exit.php

    – Sascha Frinken
    Jan 3 at 7:20











  • @SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.

    – IMB
    Jan 3 at 7:36











  • Your unit test is just a script that will return 0 as exit code when all tests pass. CI checks the return code and handles it as failed or passed.

    – Sascha Frinken
    Jan 3 at 7:42
















0















I have this basic .gitlab-ci.yml file.



image: php:7.2

before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install


tests:
script:
- vendor/bin/phpunit tests


This works just fine, it alerts me if unit tests fail or pass.



My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES! exist?










share|improve this question























  • A script returning any other exit code than 0 is treat as failed.

    – Sascha Frinken
    Jan 2 at 22:07











  • @SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just Tests: 1, Assertions: 1, Failures: 1 or OK (1 test, 1 assertion)

    – IMB
    Jan 3 at 6:33













  • php.net/manual/en/function.exit.php

    – Sascha Frinken
    Jan 3 at 7:20











  • @SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.

    – IMB
    Jan 3 at 7:36











  • Your unit test is just a script that will return 0 as exit code when all tests pass. CI checks the return code and handles it as failed or passed.

    – Sascha Frinken
    Jan 3 at 7:42














0












0








0








I have this basic .gitlab-ci.yml file.



image: php:7.2

before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install


tests:
script:
- vendor/bin/phpunit tests


This works just fine, it alerts me if unit tests fail or pass.



My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES! exist?










share|improve this question














I have this basic .gitlab-ci.yml file.



image: php:7.2

before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install


tests:
script:
- vendor/bin/phpunit tests


This works just fine, it alerts me if unit tests fail or pass.



My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES! exist?







php unit-testing continuous-integration gitlab devops






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 14:37









IMBIMB

4,350124389




4,350124389













  • A script returning any other exit code than 0 is treat as failed.

    – Sascha Frinken
    Jan 2 at 22:07











  • @SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just Tests: 1, Assertions: 1, Failures: 1 or OK (1 test, 1 assertion)

    – IMB
    Jan 3 at 6:33













  • php.net/manual/en/function.exit.php

    – Sascha Frinken
    Jan 3 at 7:20











  • @SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.

    – IMB
    Jan 3 at 7:36











  • Your unit test is just a script that will return 0 as exit code when all tests pass. CI checks the return code and handles it as failed or passed.

    – Sascha Frinken
    Jan 3 at 7:42



















  • A script returning any other exit code than 0 is treat as failed.

    – Sascha Frinken
    Jan 2 at 22:07











  • @SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just Tests: 1, Assertions: 1, Failures: 1 or OK (1 test, 1 assertion)

    – IMB
    Jan 3 at 6:33













  • php.net/manual/en/function.exit.php

    – Sascha Frinken
    Jan 3 at 7:20











  • @SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.

    – IMB
    Jan 3 at 7:36











  • Your unit test is just a script that will return 0 as exit code when all tests pass. CI checks the return code and handles it as failed or passed.

    – Sascha Frinken
    Jan 3 at 7:42

















A script returning any other exit code than 0 is treat as failed.

– Sascha Frinken
Jan 2 at 22:07





A script returning any other exit code than 0 is treat as failed.

– Sascha Frinken
Jan 2 at 22:07













@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just Tests: 1, Assertions: 1, Failures: 1 or OK (1 test, 1 assertion)

– IMB
Jan 3 at 6:33







@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just Tests: 1, Assertions: 1, Failures: 1 or OK (1 test, 1 assertion)

– IMB
Jan 3 at 6:33















php.net/manual/en/function.exit.php

– Sascha Frinken
Jan 3 at 7:20





php.net/manual/en/function.exit.php

– Sascha Frinken
Jan 3 at 7:20













@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.

– IMB
Jan 3 at 7:36





@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.

– IMB
Jan 3 at 7:36













Your unit test is just a script that will return 0 as exit code when all tests pass. CI checks the return code and handles it as failed or passed.

– Sascha Frinken
Jan 3 at 7:42





Your unit test is just a script that will return 0 as exit code when all tests pass. CI checks the return code and handles it as failed or passed.

– Sascha Frinken
Jan 3 at 7:42












1 Answer
1






active

oldest

votes


















1














The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.






share|improve this answer
























  • Ok so if I have a home-brewed tester script I simply echo 1; or echo 0; for pass and fails?

    – IMB
    Jan 3 at 16:10











  • No, echo does only print to stdout string you pass to it. For passing and failing CI it would be exit 0 and exit 1.

    – Azaradel
    Jan 3 at 16:12











  • You mean literately using exit(0); or exit(1);

    – IMB
    Jan 3 at 16:17











  • Yes. My example was from bash that's why it is without brackets.

    – Azaradel
    Jan 3 at 16:19











  • I see that. Never knew exit(); had a special purpose other than terminating the script execution.

    – IMB
    Jan 3 at 16:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008227%2fhow-does-gitlab-ci-determine-if-a-phpunit-test-pass-or-fails%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.






share|improve this answer
























  • Ok so if I have a home-brewed tester script I simply echo 1; or echo 0; for pass and fails?

    – IMB
    Jan 3 at 16:10











  • No, echo does only print to stdout string you pass to it. For passing and failing CI it would be exit 0 and exit 1.

    – Azaradel
    Jan 3 at 16:12











  • You mean literately using exit(0); or exit(1);

    – IMB
    Jan 3 at 16:17











  • Yes. My example was from bash that's why it is without brackets.

    – Azaradel
    Jan 3 at 16:19











  • I see that. Never knew exit(); had a special purpose other than terminating the script execution.

    – IMB
    Jan 3 at 16:23
















1














The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.






share|improve this answer
























  • Ok so if I have a home-brewed tester script I simply echo 1; or echo 0; for pass and fails?

    – IMB
    Jan 3 at 16:10











  • No, echo does only print to stdout string you pass to it. For passing and failing CI it would be exit 0 and exit 1.

    – Azaradel
    Jan 3 at 16:12











  • You mean literately using exit(0); or exit(1);

    – IMB
    Jan 3 at 16:17











  • Yes. My example was from bash that's why it is without brackets.

    – Azaradel
    Jan 3 at 16:19











  • I see that. Never knew exit(); had a special purpose other than terminating the script execution.

    – IMB
    Jan 3 at 16:23














1












1








1







The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.






share|improve this answer













The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 15:29









AzaradelAzaradel

1213




1213













  • Ok so if I have a home-brewed tester script I simply echo 1; or echo 0; for pass and fails?

    – IMB
    Jan 3 at 16:10











  • No, echo does only print to stdout string you pass to it. For passing and failing CI it would be exit 0 and exit 1.

    – Azaradel
    Jan 3 at 16:12











  • You mean literately using exit(0); or exit(1);

    – IMB
    Jan 3 at 16:17











  • Yes. My example was from bash that's why it is without brackets.

    – Azaradel
    Jan 3 at 16:19











  • I see that. Never knew exit(); had a special purpose other than terminating the script execution.

    – IMB
    Jan 3 at 16:23



















  • Ok so if I have a home-brewed tester script I simply echo 1; or echo 0; for pass and fails?

    – IMB
    Jan 3 at 16:10











  • No, echo does only print to stdout string you pass to it. For passing and failing CI it would be exit 0 and exit 1.

    – Azaradel
    Jan 3 at 16:12











  • You mean literately using exit(0); or exit(1);

    – IMB
    Jan 3 at 16:17











  • Yes. My example was from bash that's why it is without brackets.

    – Azaradel
    Jan 3 at 16:19











  • I see that. Never knew exit(); had a special purpose other than terminating the script execution.

    – IMB
    Jan 3 at 16:23

















Ok so if I have a home-brewed tester script I simply echo 1; or echo 0; for pass and fails?

– IMB
Jan 3 at 16:10





Ok so if I have a home-brewed tester script I simply echo 1; or echo 0; for pass and fails?

– IMB
Jan 3 at 16:10













No, echo does only print to stdout string you pass to it. For passing and failing CI it would be exit 0 and exit 1.

– Azaradel
Jan 3 at 16:12





No, echo does only print to stdout string you pass to it. For passing and failing CI it would be exit 0 and exit 1.

– Azaradel
Jan 3 at 16:12













You mean literately using exit(0); or exit(1);

– IMB
Jan 3 at 16:17





You mean literately using exit(0); or exit(1);

– IMB
Jan 3 at 16:17













Yes. My example was from bash that's why it is without brackets.

– Azaradel
Jan 3 at 16:19





Yes. My example was from bash that's why it is without brackets.

– Azaradel
Jan 3 at 16:19













I see that. Never knew exit(); had a special purpose other than terminating the script execution.

– IMB
Jan 3 at 16:23





I see that. Never knew exit(); had a special purpose other than terminating the script execution.

– IMB
Jan 3 at 16:23




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008227%2fhow-does-gitlab-ci-determine-if-a-phpunit-test-pass-or-fails%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas