Does bazel theoretically allow http requests inside bazel build rules? - bazel

Is there any possibility to write http requests in starlark build rule or via some executable invoked by ctx.actions.run ?
I know it can be done with bazel test (inside test runners), but can it be done in build phase? I know this goes against network sandboxing (but lets say we turn it off)

You can set execution_requirements to include requires-network.
Some notes:
The network requests are only within actions, they can't be run from Starlark itself
Bazel won't know to rerun actions that depend on network requests if the remote information has changed. There would need to be a way to make an action always run, which hasn't been decided on: https://github.com/bazelbuild/bazel/issues/3041

Related

Set Jenkins build cause manually via REST API

I'm looking to update the default build cause when invoking a build via the REST API. I see that this is possible by appending the cause parameter when using the Trigger builds remotely (e.g., from scripts) option, but what about when I make a /build POST request using the normal user:apiToken format?
Essentially I'm looking to replace Started by user xxxx with a custom string. I'll also accept plugin recommendations as a fallback if this isn't possible by default.

Mapping Bazel test action to remote strategy

I have a Bazel project with lots of unit tests and where a subset requires GPU support.
I would like to map the unit tests that have GPU requirements to remote strategy but keep all other unit tests as sandboxed, running locally. Since all tests share the same mnemonic (TestRunner) I am not sure how to do that using the strategy or the strategy_regexp parameters.
Is this use case supported by Bazel? Or do you have to either map all or no tests to remote execution?
Kind regards!
We had a similar problem (another flavour though: have some //some/test/target run locally while others run as remote/worker/sandboxed) and ended up writing
test --strategy=remote,worker,sandboxed # force sandbox: no local
test --strategy_regexp=//some/test/target=local # allow local
test --worker_sandboxing=true
test --incompatible_legacy_local_fallback=false
unfortunately, this regex can become quite big so consider some clever naming if you have bunch of those "exceptional" tests, e.g. call all of them _special_tag and write a regex like
test --strategy_regexp=//.*_special_tag=local # allow local for `*_special_tag
What can help to debug is to run
bazel aquery //some/test/target 2>/dev/null
to understand what actually matches on that regexp.

HTTP access to on-going Jenkins build files

I guess the title is pretty self-explanatory. The reason I want that is so that I can make a live custom HTML reporter for my tests.
My test suite takes hours to complete, and although the tests generate HTML reports as soon as each test step is executed, it's only at post-build time that those report files get published.
Being able to see them as they get generated would reduce the time it takes for me and my teammates to analyze and act upon issues revealed by our test runs.
All I need is that Jenkins let me access the build files as the build executes. Nothing fancy; I can take care of the rest. Is that possible? How?
In our setup there is always an intermediate file (typically XML) but the HTML files are created at the end of the job.
What you can do, is use the progressive output (http://jenkins/job/jobName/buildNumber/logText/progressiveText?start=0). Although you don't state which framework you use, most of them output something that would be easy to parse. e.g. "Test xxx failed".

Revert snapshot before or after each test method in a TFS build-deploy-test workflow?

I have a scenario that requires me to revert to a clean snapshot before or after each Coded UI test method is executed. I have researched using the TFS Lab Management API (see http://blogs.microsoft.co.il/shair/2011/12/22/tfs-api-part-42-getting-started-with-lab-management-api/) to revert to a specific snapshot as part of the TestInitialize and/or TestCleanup method, but I can only get this to work when executed locally. When executed on a remote machine I get errors authenticating to the TFS service.
My other option is to somehow do a 'foreach test in testrun' into the build process template (LabDefaultTemplate.11.xaml). I have identified the area that I think this would fit best, but cannot find any documentation on running a loop on each test.
Is this something that is possible, or is there somehow a built in method to accomplish this that I have overlooked?
To do what you propose you should switch to Release Management and create a separate test run for each of your groupings, in your case each test. You can use RM to orchestrate looping through each of your runs and executing then.
http://nakedalm.com/execute-tests-release-management-visual-studio-2013/
However running a UI test should not break your application and I would suggest that either your tests are way too long, or there is some flaw in the design of your application.

How to Remotely start jenkins build and get back result transactionally?

I had a request a to create a java client and start jenkins build for a specific job; and get back the result of that build.
The problem is, the system is used by multiple users and their build might messed up altogether. Also the get latest build my retrieve me the previous finished build instead of current one. Is there anyway to do build/get result transactionally?
I don't think there's a way to get true transactional functionality (in the way that, say, Postgres is transactional), however, I think you can prevent collisions amongst multiple users by doing the following:
Have your build wrapped around a script (bash, Python, or similar) which takes out an exclusive lock on a semfile before the build and releases it after its done. That is, a file which serves as a semaphore that the build process must be able to exclusively lock in order to be able to proceed.
That way, if you have a build in progress, and another user triggers one, the in-progress build will have the semfile locked, and the 2nd one will block waiting for the exclusive lock on that file, getting the lock only once the 1st build is complete and has released the lock on the file.
Also, to be able to refer to each remote build after the fact, I would recommend you refer to my previous post Retrieve id of remotely triggered jenkins job.

Resources