Is there difference `yarn dev` and `yarn run dev`? - yarnpkg

To run the local server for development I normally use yarn run dev.
But it seems yarn dev provides same function. Is this command just a short alias for yarn run dev?
I couldn't find info for yarn dev in documents.

You can leave out run from this command.
Basically, not only dev command, you can directly use any scripts by name without keyword run.
So, yarn dev and yarn run dev both do the same.

From the docs:
https://classic.yarnpkg.com/en/docs/cli/run/
It’s also possible to leave out the run in this command, each script can be executed with its name
And a similar example is given for yarn 2
https://yarnpkg.com/cli/run
Same thing, but without the "run" keyword :

Related

Error Raised Only When Using Jenkins Pipeline

I am trying to setup a Jenkins pipeline using scripted pipeline with a windows 2019 server, however I ran into this error while trying to build
> webpack --config ./config/webpack-cli-prod.config.js
C:\myProject\node_modules\webpack\lib\javascript\JavascriptModulesPlugin.js:143
throw new TypeError(
^
TypeError: The 'compilation' argument must be an instance of Compilation
at Function.getCompilationHooks (C:\myProject\node_modules\webpack\lib\javascript\JavascriptModulesPlugin.js:143:10)
at SourceMapDevToolModuleOptionsPlugin.apply (C:\myProject\node_modules\webpack\lib\SourceMapDevToolModuleOptionsPlugin.js:50:27)
at C:\myProject\node_modules\webpack\lib\SourceMapDevToolPlugin.js:163:53
at Hook.eval [as call] (eval at create (C:\myProject\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:100:1)
at Hook.CALL_DELEGATE [as _call] (C:\myProject\node_modules\tapable\lib\Hook.js:14:14)
at Compiler.newCompilation (C:\myProject\node_modules\webpack\lib\Compiler.js:1122:26)
at C:\myProject\node_modules\webpack\lib\Compiler.js:1166:29
at Hook.eval [as callAsync] (eval at create (C:\myProject\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\myProject\node_modules\tapable\lib\Hook.js:18:14)
at Compiler.compile (C:\myProject\node_modules\webpack\lib\Compiler.js:1161:28)
I tried to run same command/step using freestyle Jenkins job, and it works without this error.
I tried to run the same command on the Jenkins agent locally, and it works without this error.
I looked up on google, and came across this link here, I tried to use newer version of html-webpack-plugin, and we also tried to build without the plugin. All come to the same result, that the error would occur only when running from Jenkins scripted pipeline.
I also tried with a different server, while keeping the same agent and job configuration, and I also get the same error.
The version of npm is 8.11.0, the node version is 16.16.0. The agent is connected through running the agent.jar file from the agent.
The only difference I see between the freestyle job and the scripted pipeline job is the freestyle job appears to be run as SYSTEM by the Jenkins server, whereas the pipeline job is probably run with lower privilege (I am not entirely sure though). I saw also this post, where it says
in the Freestyle job everything is executed in the agent, but for the Scripted Pipeline Job, the pipeline code is translated in the controller to atomic commands that are sent to the agents.
But I have no idea how to make the scripted pipeline job run just like the freestyle job.
On one hand, it appears to have to do with webpack, and on the other it appears to be related to Jenkins since running freestyle and locally on the server is without errors.
This is how my Jenkins scripted pipeline looks like (with sensitive information removed)
node("My-Server"){
dir("C:\\MyProject"){
stage('Pre-Test Build Client (Web)') {
dir("aFolder"){
bat 'npm run build-all-prod' // This is the script that invoke the webpack build command
}
}
}
}
I have run out of options, and do not where to go from here, and I couldn't find any more information on google that would be helpful. Any help here would be really appreciated. Thank you.
I'm not sure if jenkins creates the same environment variables, and command line tools (you can configure some on the node's configuration page). I would check if the node's environment variables and tools are the same in freestyle vs pipeline job by running something like this in each job, and comparing the output:
bat 'echo %PATH%'
bat 'which webpack'
bat 'npm list webpack'
Another thing worth checking is whether you're using batch script in both jobs, and not eg shell in freestyle.
Lastly I found a gh issue whith the same error as you, caused by having 2 different installations of webpack, one on v5. May be worth looking into, if everything else fails.

How to run pre/post job scripts on self-hosted GitHub Actions runner

Problem
I am trying to use a Windows Docker container to run GitHub Actions.
I want to run scripts before and after the job (e.g. to clean the directory).
I have successfully done this before on a computer not running docker, so I figured the same should work in docker.
What I have tried
I found here that you can do that using Environment Variables.
I used the following two commands in command prompt to set the environment variables.
Pre-Job Script:
setx ACTIONS_RUNNER_HOOK_JOB_STARTED C:\actions-runner-resources\scripts\pre-post-build\pre-run-script.ps1
Post-Job Script:
setx ACTIONS_RUNNER_HOOK_JOB_COMPLETED C:\actions-runner-resources\scripts\pre-post-build\post-run-script.ps1
The scripts do not run.
I have tried restarting the docker container.
I have tried restarting the actions runner service.
I am new to docker, so I am wondering if I am doing something wrong with the environment variables that does not work with docker.
How do I get the actions runner to run pre/post job scripts in docker?
You can safely add them to your environment variable by doing this recommended method;
Inside the actions-runner directory, locate the .env file, edit it by adding your environment variable. Save and restart the runner service.

Programmatically run cypress tests on docker

I am currently running cypress tests using:
await cypress.run({config inserted here})
Wondering if there is a way to spin up one of cypress's docker containers and then point the cypress tests there using the statement above. The suggestions online are to run the tests using command line, but I'm hoping to still be able to use cypress.run() and perhaps pass in an option that tells cypress to point the tests to a container?
Cypress docker containers will invoke cypress run by default. To change that, you'll need to override the container entrypoint to invoke node instead of cypress, and then pass your script file that's invoking cypress via the module api (cypress.run()) as the container command. You could do this via the command line, but it's a bit long because of all the options you'll need to pass:
# Assumes you're running this from the Cypress project directory on the host machine
$ docker run -it --rm -v $PWD:/tests -w /tests --entrypoint "/usr/local/bin/node" cypress/included:3.2.0 "myScript.js"
Warning: you're mounting in your npm dependencies with this method, which might cause problems if any of them were compiled on a different os like Windows.

How do I send baseUrl as a parameter with Cypress.io

I am researching switching from Protractor to Cypress.io.
I have some tests up and running, however, I want to be able to send the baseUrl as a parameter as I can with Protractor.
I have tried:
$ npm run cypress:open --config "baseUrl=myUrl" --still uses the baseUrl from my config file.
$ npm run cypress:open --env "baseUrl=myUrl" --still uses the baseUrl from my config file.
and a host of other things, none of which work quite right.
I want to be able to pass a parameter to my command which gives me the flexibility to choose which environment I am running my tests in. I can do this with Protractor, with a command like this:
$ ng e2e --suite testSuite --baseUrl myUrl
What is the equivalent for Cypress.io?
You have to set the env variable CYPRESS_baseUrl
CYPRESS_baseUrl=[your baseUrl] npm run cypress:open should do it for you
I think the correct way to do this is:
$ npm run cypress:open -- --config "baseUrl=myUrl"
Otherwise, the config parameter is passed to npm instead of cypress. Notice the extra --
Good luck!
Brendan's answer is correct.
I would like to add that
$ npm run cypress:open --config "baseUrl=myUrl"
may not be working since you try to propagate some configuration into a command inside your package.json.
If instead you'd do for example:
$ ./node_modules/.bin/cypress run --config baseUrl=myUrl
it should work just fine.
This is good to know since it will let you use additional CLI options as well (which you do not know ahead of time).
PS: --env wouldn't work for baseUrl since baseUrl is a built-in configuration value and not a regular env variable.
What I did was simply:
export CYPRESS_BASE_URL=SOME_OTHER_URL
yarn cypress run
This will override the baseUrl configuration. See: https://docs.cypress.io/guides/guides/environment-variables.html#Overriding-Configuration

Commands on hosts when docker is up?

Is there a possibility to run some commands on host when my docker-compose up is running?
In my case I am building a set of containers for 2 projects and some of containers are facilitating frameworks tools or phing for migrations and other tasks. I'd like to prepare a set of aliases to be able to run some common tasks from host level instead of running docker-compose exec web command just write drun command or something like that.
For now I came up with a build.sh where I would define a set of such aliases and then run docker-compose up but is there easier way for that?

Resources