tag:help.appveyor.com,2012-11-13:/discussions/problems/6457-artifacts-are-not-pushed-after-tests-failAppVeyor: Discussion 2018-10-19T08:18:18Ztag:help.appveyor.com,2012-11-13:Comment/423352712017-04-10T18:32:42Z2017-04-10T18:32:42ZArtifacts are not pushed after tests fail<div><p>Hi Leonardo,</p>
<p>I see few ways to workaround this:</p>
<ul>
<li>
<p>Upload artifacts with <a href="https://www.appveyor.com/docs/packaging-artifacts/#pushing-artifacts-from-scripts">script</a> at <code>on_failure</code> stage in <a href="https://www.appveyor.com/docs/build-configuration/#build-pipeline">pipeline</a> and leave <code>artifacts</code> section untouched. Thus build will use <code>artifacts</code> section on sunny day and <code>on_failure</code> when some test failed.</p>
</li>
<li>
<p>Upload artifacts with <a href="https://www.appveyor.com/docs/packaging-artifacts/#pushing-artifacts-from-scripts">script</a> at <code>on_finish</code> stage in <a href="https://www.appveyor.com/docs/build-configuration/#build-pipeline">pipeline</a> and remove <code>artifacts</code>. This will behave like <code>finally</code> statement on regardless of tests success.</p>
</li>
<li>
<p>Wrap tests to PowerShell script and <a href="https://www.appveyor.com/docs/running-tests/#uploading-xml-test-results">upload test results</a> in the end of this script. As long as upload test results step is happy, the whole <code>test_script</code> is happy so build flow will reach artifact upload stage.</p>
</li>
</ul>
<p>Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/423352712018-06-15T15:23:54Z2018-06-15T15:23:55ZArtifacts are not pushed after tests fail<div><p>Hey Ilya,</p>
<p>I have an Appveyor job that starts up client and server processes that talk to each other then runs end-to-end tests. Both processes generate log files that are invaluable for debugging should the tests fail. I am using the newly launched Linux VMs to run my tests (I am not able to use Powershell cmdlets or the appveyor binary to upload the logs as artifacts). I tried to follow the instructions in the link you provided to upload the log files via the build worker API, but have so far not been successful:</p>
<ul>
<li>The url I get back from the API is a 'windows.net' url (Azure), which is not mentioned in the <a href="https://www.appveyor.com/docs/build-worker-api/#push-artifact">API docs</a></li>
<li>When I try to upload a file using the Azure url, I get back a 403 (Forbidden):</li>
</ul>
<pre>
<code>In [1]: import requests
In [2]: import urlparse
In [3]: api_url = "http://localhost:59911/api/artifacts"
In [4]: metadata = {"path": "/home/appveyor/projects/grr-1r2v0/e2e.log", "name": "Test Log (Manual)"}
In [5]: resp = requests.post(api_url, json=metadata)
In [6]: resp.content
Out[6]: '{"uploadUrl":"https://appveyorcidata.blob.core.windows.net/demonchild2112-67630/grr-1r2v0/71/vjv88ghbkwli15vh/e2e.log?sv=2015-12-11&sr=c&sig=tUz4mdgx1bpnmb%2FbB%2F5fEV4df2YgeCuZm9JP04kS0IY%3D&st=2018-06-15T14%3A41%3A44Z&se=2018-06-15T14%3A52%3A44Z&sp=rw","storageType":"Azure"}'
In [8]: import json
In [11]: upload_url = json.loads(resp.content)['uploadUrl']
In [13]: files = {'file': open('/home/appveyor/projects/grr-1r2v0/e2e.log', 'rb')}
resp = requests.put(upload_url, files=files)
In [16]: resp.status_code
Out[16]: 403</code>
</pre>
<p>What I am doing wrong? Is there an easier way of uploading artifacts produced by Linux Builds?</p>
<p>FWIW, I think it would be really useful to have an Appveyor config option (boolean) that determines whether to upload artifacts despite tests failing.</p>
<p>Best,</p>
<p>Denver</p></div>denvertag:help.appveyor.com,2012-11-13:Comment/423352712018-06-15T19:39:23Z2018-06-15T19:39:23ZArtifacts are not pushed after tests fail<div><p>I am not sure I agree with the very first statement "I am not able to use Powershell cmdlets or the appveyor binary to upload the logs as artifacts". Both <code>appveyor PushArtifact</code> and <code>Push-AppveyorArtifact</code> described <a href="https://www.appveyor.com/docs/packaging-artifacts/#pushing-artifacts-from-scripts">here</a> works on Linux VMs. It can look like this:</p>
<pre>
<code>on_failure:
- sh: appveyor PushArtifact <relative_path_to_log></code>
</pre>
<p>or this:</p>
<pre>
<code>on_failure:
- ps: Push-AppveyorArtifact <relative_path_to_log></code>
</pre>
<p>Can you please try that and let us know if this works?</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/423352712018-06-15T19:43:42Z2018-06-15T19:44:39ZArtifacts are not pushed after tests fail<div><p>After looking closer on your post I think that <code><relative_path_to_log></code> can be simple set as <code>e2e.log</code> as it seems to be in the root of your build folder (assuming you do not change directory as part of some build script).</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/423352712018-06-15T21:23:00Z2018-06-15T21:23:01ZArtifacts are not pushed after tests fail<div><p>Adding the appveyor command directly in the yaml config worked. Previously, I tried invoking the command in a shell script, but that <a href="https://ci.appveyor.com/project/demonchild2112/grr-1r2v0/build/25">failed</a> because it wasn't in the PATH, so I assumed the CLI tool wasn't implemented for Linux yet. Thanks for the pointer!</p></div>denvertag:help.appveyor.com,2012-11-13:Comment/423352712018-06-15T21:31:09Z2018-06-15T21:31:09ZArtifacts are not pushed after tests fail<div><p>I think you could keep it in script, just add <code>-E</code> flag to <code>sudo</code>: <a href="https://stackoverflow.com/a/8633575/6733637">https://stackoverflow.com/a/8633575/6733637</a></p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/423352712018-06-20T11:06:48Z2018-06-20T11:06:49ZArtifacts are not pushed after tests fail<div><p>Worked. Thanks!</p></div>denver