WebStorm run/debug allow multiple scripts - intellij-idea

Using the "Run/Debug Configurations" tool in WebStorm, I would like to create one script that ends up running multiple npm scripts. For example, I would like to create a single script that will end up executing npm run script-one && npm run script-two.
Is this possible?

You can use Compound type of Run/Debug Configuration.
https://www.jetbrains.com/help/webstorm/creating-compound-run-debug-configuration.html
https://www.jetbrains.com/help/webstorm/run-debug-configuration-compound-run-configuration.html
For example, you may want to run the sequence of several test configurations, or run several configurations of different types (for example, JavaScript, HTML, etc). WebStorm provides you with the dedicated capability for that: a compound Run/Debug configuration. Compound configuration can include multiple configurations of the same or different type with the same or different specified targets.
When you run or debug your code using a compound configuration, you actually launch a sequence of configurations it includes in order they are listed.
Another possible idea: use "Before launch" section to run some other tasks before executing current one: https://www.jetbrains.com/help/webstorm/run-debug-configuration-npm.html#before-launch-options

Related

How to run configurations one after another in Intellij?

I'm trying to create a compound/multirun run configuration in intellij where each configuration runs sequentially. I've tried with both compound and multirun, however it appears that neither allow configurations to be run one after the other (as in the second waits for the first to finish).
Is there any way to do this?
There are related requests for Compound configuration: https://youtrack.jetbrains.com/issue/IDEA-166035 and for Multirun plugin: https://github.com/rkhmelyuk/multirun/issues/63
This is possible by using the plain Before Launch settings of a Run Configuration. There you can specify one or more other Run Configurations. These will run sequentially before running the original Run Configuration.

Run cucumber by right clicking on it in IntelliJ

I am trying to simplify the way we run cucumbers. We have a runner for each folder and we always change the runner in a run configuration that has some VM options set.
I can right click on a feature, select "Run feature :" but it doesn't run successfully without the parameters from the run configuration (one of them runs the tests with an in memory database for example)
Is there anyway I can add a default configuration so I can run them directly?
Run -> Edit Configurations
In the left-hand panel, there is a category called defaults. You can set the defaults to cucumber there. However, note that you might have to delete your previously existing configurations to get this to work with files you've already tried. They usually appear in a faded gray.
In addition, you could also add a runner class, which can run (a subset of) your tests from a testing framework. You can provide #CucumberOptions in this runner.

How to run multiple IntelliJ IDEA configurations after one another (serially, sequentially)?

Similar to this question, I want to run multiple Run Configurations as one. However, instead of running them simultaneously (parallel), I want to run them after one another in a specific order.
I know I can select another Run Configuration to run before another, like answered here, but approach has one issue: it's not possible to have one generic/main/super Run Configuration that runs nothing else than the specified run configurations. I must to pick one project-specific configuration (e.g. a Python configuration in PyCharm, the JetBrains Python IDE similar to IntelliJ IDEA) to be able to choose Run Configurations to run serially before the main one. This is an issue, because if I ever want to change to or insert a different configuration where the main Python Run Configuration is, I need to remake the Run Configuration Order besides a new one. With a predefined serial list of Run Configurations to execute, this would be as simple as inserting another configuration in the list.
Is this possible and how do I achieve this?
Besides the Before launch functionality mentioned in the question, there is no such possibility in IntelliJ IDEA and other JetBrains IDEs to my knowledge. However, there exists plugins that add Run Configurations that initially do nothing (empty), which can be considered as a generic/main/super Run Configuration. In such a configuration the regular way of specifying other configurations to run sequentially before launch can be used to achieve the question's goal.
An example of a plugin that adds an initially empty Run Configuration is the Multirun plugin. Don't be confused by its name: it's meant to run multiple Run Configurations simultaneously with the option to start them sequentially, but it does not wait for earlier ones to finish before starting the later ones. Just add the default (empty) Multirun configuration and queue up other tasks to run sequentially through the Before launch section.
It's a pity JetBrains haven't added a serial/sequential execution configuration in their Compound Run Configuration, which basically achieves what the Multirun plugin achieves: simultaneous / parallel execution. With compound run configurations, the Run Configuration editor would become a really powerful but simple to program configurations for various wishes like Gradle achieves for more complex build configurations.

Using Tomcat Maven plugin with multiple servers

I've looked at the usage, but haven't understood from it how to configure multiple servers. I added separate server elements to settings.xml - but I don't understand how to specify a different URL for every server.
The URL element belongs to the global plugin configuration. How do I configure multiple server URLs?
You could add multiple profiles to your pom.xml. One for each server. Check the Maven documentation on profiles for details!
If you examine the documentation of the Tomcat plugin you will see that it does not support multiple <configuration> sections. That should be a small addition because in the deploy phase you only copy the WAR file to the server using an HTTP PUT command. So I wonder why they have not added this capability to the plugin.
Anyhow, one possible workaround is to:
Make multiple copies of your pom.xml in the same directory but give them unique names, e.g. dev_1_pom.xml, or dev_<some_machine_name_or_IP>, qa_1_pom.xml ..... You can keep your development pom.xml file name the same because you will likely still run Maven from the command line. Personally, I prefer running the mvn command from my IDE (a button click away vs. typing an mvn command with arguments every time).
In each of the copies, change the <configuration> section under your Tomcat plugin to point to a different server that matches the name of your specific pom.xml. You will need corresponding sections in settings.xml
Create corresponding External Tools Configuration(s) (Eclipse, or other IDE) and each one call the corresponding POM file. Here is an example with Eclipse:
Open External Tools Configuration Dialog in Eclipse (either from the dropdown menu next to the button, or by going to the menu bar and clicking Run > External Tools > External Tools Configurations). Then on the Main Tab, provide values for the following fields
Location: C:\downloads\tools\apache-maven-3.0.3\bin\mvn.bat
Working directory: ${workspace_loc:/<project_name>} - replace <project_name> with the name of your project
Arguments: -f <pom_file_name> <other_arguments> - <other_arguments> could be tomcat7:redeploy
Now you can run these external tool launchers individually to deploy to different servers.
Optionally, extract the mvn commands from your launchers and create a shell script (batch or Unix bash script) that runs all of them. That way you can deploy to multiple servers at once. You can also run this script from Eclipse. Create a new External Tools Configuration launcher but this time your Location: field will point to cmd (Windows) or bash (Unix, Linux ...), not mvn

Using a variable obtained using a pre-build shell command to set an option for the Maven build in Hudson

I have a Hudson job that runs a maven goal. Before this maven goal is executed I have added a step to run before the build starts, it is a shell script that obtains the version number that I want to use in the 'Goals and options' field.
So in my job configuration, under Build Environment I have checked the Configure M2 Extra Build Steps box and added a shell script before the build. The script looks like this:
export RELEASE={command to extract release version}
echo $RELEASE
And then under the Build section I point to my 'root pom'. In the Goals and options I then want to be able to do something like this:
-Dbuild.release.version=${RELEASE} deploy
Where build.release.version is a maven property referenced in the POM. However since the shell doesn't seem to make its variables global it doesn't work. Any ideas?
The only one I have is to install the Envfile plugin and get the shell script to write out the RELEASE property to a file and then get the plugin to read the file, but the order in which everything is run may cause problems and it seems like there must be simpler way...is there?
Thanks in advance.
I recently wanted to do the same, but AFAIK it's not possible to export values from a pre-build shell to the job environment. If there is a Hudson Plugin for this I've missed it.
What did work, however, was a setup similar to what you were suggesting: having the pre-build shell script write the desired value(s) to a property-file in the workspace, and then using the Parametrized Trigger Plugin to trigger another job that actually does the work (in your case, invoke the Maven job). The plugin can be configured to read the parameters it passes from the property file. So the first job has just the shell script and the post-build triggers, and the second one does the actual work, having the correct parameters available as environment variables.
General idea of the shell script:
echo "foo=bar
baz=`somecmd`" > build.properties
And for your Goals and options, something like:
-Dbuild.release.version=${foo} deploy
Granted, this isn't as elegant as one might want but worked really well for us, since our build was broken into several jobs to begin with, and we can actually reuse the other jobs that the first one triggers (that is, invoke them with different parameters).
When you say it doesn't work, do you mean that your RELEASE variable is not passed to the maven command? I believe the problem is that by default, each line of the shell script is executed separately, so environment variables get lost.
If you want the entire shell script to execute as if it was one script file, make the first line:
#!/bin/sh
I think this is described in the Help information alongside the shell script build step (and if I'm wrong, that's a good place to look for the right syntax).