Publish files to artifacts
When you are running your deployments, as everything is being executed in docker containers, you will probably want to save some generated files, like reports files, application files, configuration files, etc. so you can use or check them later.
You can do this by using the artifacts repositories, which are the only connection between the different containers where you are executing in your jobs and your Clarive, so files do not get lost when the container finish.
Keep in mind this is an example about how you can configure it. So the configuration does not need to be the same for all projects or repositories.
Once we have our artifacts repository configurated, we can now call the service into our rule yaml so it will store the file into the repository in the jobs execution.
In this example, we will generate an example application with maven in our
build
phase, and then, we will store the application file into our artifacts
repository.
build: do: # These commands will download an example application from Maven and compile it. - | mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false cd my-app mvn package
Now that we have the file generated into the container where we are executing the job, we want to save it into the artifacts repository, so the file will not dissapear when the container execution finishes.
To do so, we will use the publish service to store the file in our deploy phase. We will also store our repository url into a variable.
The different parameters are:
- repository - Write the repository name where you want to save your file.
- to - Path inside the repository where the file will be stored. Including filename.
- from - Path for the file you want to store into the repository.
deploy: do: - artifact_repo = publish: repository: repository-name to: '/maven/apps/my-app-1.0-SNAPSHOT.jar' from: '/my-app/target/my-app-1.0-SNAPSHOT.jar' - echo: ${artifact_repo.url}
With this small example we would have a job rule like this in our clarive.yml:
image: maven build: do: - | mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false cd my-app mvn package deploy: do: - artifact_repo = publish: repository: repository-name to: '/maven/apps/my-app-1.0-SNAPSHOT.jar' from: '/my-app/target/my-app-1.0-SNAPSHOT.jar' - echo: ${artifact_repo.url}
So when this job finish, if everything went correctly, we will be able to see our stored file in our artifacts repository from Clarive. An also we should have an output with the url for the stored file.